<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Linanurullaili on Medium]]></title>
        <description><![CDATA[Stories by Linanurullaili on Medium]]></description>
        <link>https://medium.com/@linanurullaili_90897?source=rss-a02bb2181160------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yVzbCDUfQxTQfJPNVqCL9Q.jpeg</url>
            <title>Stories by Linanurullaili on Medium</title>
            <link>https://medium.com/@linanurullaili_90897?source=rss-a02bb2181160------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 02:43:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@linanurullaili_90897/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[DATETIME IN PYTHON]]></title>
            <link>https://medium.com/@linanurullaili_90897/datetime-in-python-d9a64dc8c88a?source=rss-a02bb2181160------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9a64dc8c88a</guid>
            <category><![CDATA[function-datetime-python]]></category>
            <category><![CDATA[python-datetime]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[datetime]]></category>
            <dc:creator><![CDATA[Linanurullaili]]></dc:creator>
            <pubDate>Sun, 26 Dec 2021 09:41:01 GMT</pubDate>
            <atom:updated>2021-12-26T09:41:01.354Z</atom:updated>
            <content:encoded><![CDATA[<p>Datetime is a library provided in python programming to access date and time. Generally datetime is denoted<em> yyyy-mm-dd hh:mm:ss</em>. There are two ways to call it:</p><p><em>import datetime</em></p><p>Or you can also use the method with the command:</p><p><em>from datetime import *</em></p><p>The difference in how to call the datetime above can be seen from the form of the datetime function call. There are many datetime functions in python, here are the functions in python.</p><p><strong>1.</strong> <strong>Function now()</strong></p><p>The function <em>now()</em> in python datetime is used to find out the date and time the program was executed by the computer. To use it, the first datetime method call using the function <em>now()</em> is <em>n = datetime.datetime.now(). </em>Where <em>n</em> is a variable used for example in the command<em> print()</em> so that the output appears. While the use of the second datetime calling method is <em>n = datetime.now()</em> where <em>n</em> is an example variable. It can be concluded that the use of the second method of calling the datetime function is more concise. The following is an example of using the function<em> now()</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*D7ZPCpouHK1jOnkL_JYL6w.png" /></figure><p>In the picture above is an example of using the function<em> now()</em>. The output of the above program is the date and time when the program was run. Can be seen there is a difference of a few seconds when running the program between the first and second programs. And it can be seen that the default datetime format is <em>year-month-date hours:minutes:seconds</em>. In the function <em>now()</em> this can be done if you just want to change the date format so it doesn’t look like that. Here’s how to change the default format of the function<em> now()</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*uueS9nlmN7LcXoPUxA6YaQ.png" /></figure><p>In the picture above is an example of using the now() function with the format <em>dd-mm-yyyy</em>. In the example program, we call the variable <em>skrg</em> whose contents are the command function <em>now(). </em>To read the day format we can use <em>skrg.day</em>, if the month we use <em>skrg.month</em>, and if the year we use <em>skrg.year</em>. in the function<em> now()</em>, we can also retrieve the date, month, and even year. The following is an example of using the function<em> now()</em> which only uses one of the default formats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*pt1TzOA74J-T1kAvR2ElIw.png" /></figure><p>In the image above is the format for retrieving functions, for example calling the date, then month, and year properties separately. In addition to using the function<em> now()</em>, we can also use the function<em> today()</em>. The method is not much different from the function<em> now()</em>, where<em> n = datetime.datetime.today() / n = datetime.today() </em>where <em>n</em> is the variable. The following is an example of using the function<em> today()</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*3M22uclfAQfBvSFCCfgUTA.png" /></figure><p><strong>2.</strong> <strong>Function date()</strong></p><p>The function<em> date()</em> is a function used to determine the date from the date and time array form. Usually the default format in using the function<em> date()</em> is <em>year — month — date/ day (yyyy-mm-dd)</em>. For example, if we combine it with the function<em> now()</em>, how to use the function<em> date()</em> is <em>n = datetime.date(datetime.now())</em> where <em>n</em> is an example variable and the one in brackets is the formula for the function<em> now()</em> itself. The following is an example of using the function<em> date()</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*p1U7w03Z7ODARe1avt3SFQ.png" /></figure><p>In the image above we are calling datetime in a python program. Then we enter the function<em> date()</em> formula along with the function<em> now()</em> formula using the variable <em>skrg</em>. Then the command<em> print()</em> to call the variable <em>skrg</em>. It can be seen that the output is just a date.</p><p><strong>3.</strong> <strong>Function time()</strong></p><p>The function<em> time()</em> is used to determine the time from a date and time array. Usually the default format for using the function<em> time()</em> is <em>hours:minutes:seconds</em>. For example, if we combine it with the function<em> now()</em>, how to use the function<em> time()</em> is <em>n = datetime.time(datetime.now())</em> where <em>n</em> is an example variable and the one in brackets is the formula for the function<em> now()</em> itself. The following is an example of using the function<em> time()</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*4nsjQiPudPiE4Vz64IyT-Q.png" /></figure><p>In the image above we are calling datetime in a python program. Then we enter the function<em> time()</em> formula and it is accompanied by the function<em> now()</em> formula using the variable <em>waktutoday</em>. Then command<em> print() </em>to call variable <em>waktutoday</em>. It can be seen that the output only shows the time when the program was run.</p><p><strong>4.</strong> <strong>Function timedelta()</strong></p><p>The function<em> timedelta()</em> is a function that is used to determine <em>n</em> days, both the day before and the day after the program is run. The function<em> timedelta()</em> is not only used to specify <em>n</em> days. But can be used to specify <em>n</em> times and so on. The way to use this function is <em>n = datetime.date(datetime.now()) </em>where <em>n</em> is the sample variable for the function <em>now()</em> followed by the function<em> now()</em> formula. Then how to use the formula <em>timedelta()</em> is <em>a = n + (timedelta(day=b))</em> where <em>a</em> is the sample variable and <em>n</em> is the variable from the formula function <em>now()</em> then <em>b </em>is the specified <em>n</em> day. The following are the parameters in the function<em> timedelta() </em>in addition to the parameter day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*VB8JAVLh2jY0PCrbtNgPkQ.png" /></figure><p>The table above is the parameters in the function<em> timedelta()</em>. The following is an example of using the function<em> timedelta()</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*NEYi29HVZJasbVeOdY7-JA.png" /></figure><p>In the image above <em>‘skrg’ </em>is the date variable when the program is run, so ‘<em>a’</em> is the example variable for using the function<em> timedelta()</em>. Then ‘<em>days’</em> to describe the day and ‘4’ to describe the ’n’ days after the day the program was run.</p><h4>Example problem/case study</h4><p>From the presentation of the material above, we can apply it in learning in everyday life. The following is an example of a case study of the list data type that is around us.</p><p>Create a diffDate(x) function that is used to calculate the difference in days from today’s date and x’s date (in string format ‘YYYY-MM-DD’). The function returns an integer which is the difference between date x and today’s date. Example:</p><p>Suppose today’s date is ‘2018–12–26’, then if the function is called with diffDate(‘2018–12–30’) it will return the value 4.</p><p>From the above case study, the script below can be obtained.</p><p><em>from datetime import *</em></p><p><em>def diffDate(x):</em></p><p><em>skrg = datetime.now()</em></p><p><em>a = str(skrg.year)+’-’+str(skrg.month)+’-’+str(skrg.day)</em></p><p><em>tgl = datetime.strptime( a, ‘%Y-%m-%d’)</em></p><p><em>date = datetime.strptime( x, ‘%Y-%m-%d’)</em></p><p><em>y = date — tgl</em></p><p><em>print(y.days)</em></p><p><em>return y.days</em></p><p><em>diffDate(‘2021–12–11’)</em></p><p>In the script above, it can be explained that before we have to call the datetime function, we use the command <em>from datetime import *</em> then we use the def function with the name ‘diffDate’ with the parameter ‘x’ we can write <em>def diffDate(x ):.</em> Which in the function contains an example variable named ‘skrg’. In the variable ‘skrg’ we enter the formula function <em>now()</em> then in the formula we create a string format for the date by creating a new variable named <em>a</em>. then on the ‘tgl’ variable we make the variable arrangement format <em>a</em> on the date arrangement. then our variable ‘date’ creates collation format for parameter ‘x’ on date. And then the variable <em>y</em> is an example for the difference between date <em>x</em> and today’s date. Followed by the command <em>print(y.days)</em> because it will only take the format of the day. And for the function call, we use the return value, which is <em>return y.days, </em>which we then call with <em>diffDate(‘2021–12–11’)</em> which is enclosed in a string format.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9a64dc8c88a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FUNCTIONS IN PYTHON]]></title>
            <link>https://medium.com/@linanurullaili_90897/functions-in-python-e7304f83682f?source=rss-a02bb2181160------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7304f83682f</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[funtions-python]]></category>
            <dc:creator><![CDATA[Linanurullaili]]></dc:creator>
            <pubDate>Sun, 26 Dec 2021 09:18:54 GMT</pubDate>
            <atom:updated>2021-12-26T09:18:54.531Z</atom:updated>
            <content:encoded><![CDATA[<p>A function is a collection of commands in python grouped together that are used to perform an action. These functions start with the command def() then the function name and then followed by parentheses and a colon. If you want to include parameters or arguments, you can put them in parentheses.</p><p><strong>1.</strong> <strong>Some Form When The Function Is Called</strong></p><p>Functions are used to execute commands as specified. There are various ways to call the function itself. If there are no parameters, then use the <em>n()</em> method where <em>n</em> is the name of the function itself. The following is an example when calling a function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*WBrgIBbMRPYWdsAMcJVV3A.png" /></figure><p>In the picture above to call a function we use the def() command followed by the name “function” and after that it is bracketed and then a colon (:). Inside the function there are several command blocks, namely:</p><p><em>print(‘Hello I Like Python’)</em></p><p><em>print(‘Do you like it too?’)</em></p><p><em>print(‘I hope you feel it’)</em></p><p>From the command block above, the following results are obtained.</p><p><em>Hello I Like Python</em></p><p><em>Do you like it too?</em></p><p><em>I hope you feel it</em></p><p>The example function above is a function that has no parameters and is only called once. The parameter itself serves as input in the function command. Parameters are placed in parentheses after the function name. Then the function call with parameters is with n(a) where n is the name of the function and a is the value of the parameter data. The following is an example of a function that takes parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*8nJM6p2Ey_GLsLdIH7S48A.png" /></figure><p>In the image above, calling the function with parameters. This is followed by the function name “myhobby” and the parameter “hobby”. Inside the function there is a command block as follows.</p><p><em>print(‘Hello… My name is Lina’)</em></p><p><em>print(‘I have a hobby is ‘ + hobby)</em></p><p><em>print(‘What kind of hobbies do you have?’)</em></p><p>In the command there is an input “hobby” because the parameter is named “hobby”. So, the function call itself must be accompanied by the value of the parameter to be assigned a value. In the image the function with the name “myhobby” is given the value “Read and Write”. Then the result of the above function call is:</p><p><em>Hello… My name is Lina</em></p><p><em>I have a hobby is Reading and Write</em></p><p><em>What kind of hobbies do you have?</em></p><p>From the above results, the “hobby” parameter data value will be printed according to the “hobby” input which is located after the “is” sentence.</p><p>2. <strong>Functions Used in Arithmetic Operations</strong></p><p>Functions can also be used in arithmetic operations by providing as much parameter data in parentheses as required in the operation. Here we can use the usual parameter method with <em>n(a,b)</em> where <em>n</em> is the name of the function and <em>a</em> is the first parameter data, then <em>b </em>is the second parameter data. And in that function there is a command <em>print()</em> so that the output can be printed. In using this arithmetic operation function, there can be more than two parameter data. We can also use another way, namely by using a <em>return value</em>, namely by <em>return n</em> where <em>n</em> is the variable used in this arithmetic operation function. The following is an example of using arithmetic operations functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*4J41kYdINK74hhXEBZYgqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*1KzpWqbJNpQGCnluqpdJbg.png" /></figure><p>In the picture above is an arithmetic operation function that uses the usual parameter method and uses the return value method. The function above is named <em>penjumlahan()</em> where there are two parameters, namely <em>a</em> and <em>b</em>, separated by commas. if you use the usual parameter method, then in the function there must be a command <em>print()</em> first so that later when calling the function the results in the output can be printed. In this return value, there are two ways, namely the existence of <em>a</em> variable for the data of parameter <em>a</em> and variable <em>b</em> for the value of parameter <em>b</em>. After the return command, how to call the function with <em>print(a, ‘+’, b, ‘=’, penjumlahan(a, b))</em> so the <em>a</em> and<em> b </em>parameter values ​​in the print command are not changed or fixed. Then there is another direct method, namely after the return command using the <em>print(penjumlahan(a,b)) </em>command where <em>a </em>and <em>b</em> are the parameter values, namely 9 and 10. Then the output of the above command is.</p><p><em>9 + 10 = 19 →The result of the first function example</em></p><p><em>9 + 10 = 19 →The result of the second function example</em></p><p><em>19 →The result of the third function example</em></p><p>3. <strong>Function Parameters With Default Value</strong></p><p>In the function parameters, we can provide a default value, meaning that if when we call the function we do not provide a value from the parameter data, the value that will appear is the default value. By using the <em>operator (=)</em>, for example<em>, def n(a, b=0):</em> where <em>n</em> is the name of the function and <em>a</em> is the first parameter, <em>b</em> is the second parameter with a default value of 0. Parameters with default values ​​must be placed after parameters that do not have default values. Here is the use of the function with the default value parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*8wPNWzy617vKs0dmoudOsg.png" /></figure><p>In the image above there is a function whose parameters are default values. In the first function, <em>penjumlahan()</em> the default value of parameter <em>b</em> is given 0. So if at the time of calling the function if the value of parameter <em>b</em> is not given, the value will automatically be zero. And like the second function, <em>penjumlahan()</em> the default value of parameter <em>b</em> is assigned a value of 0 and <em>c</em> is assigned a value of 1. So if parameters <em>b </em>and <em>c </em>are not assigned a value, the default value will appear. From the function above, the following results can be obtained.</p><p><em>9 + 10 = 19 → The result of the first function penjumlahan(9, 10)</em></p><p><em>17 + 0 = 17 → The result of the first function penjumlahan(17)</em></p><p><em>12 + 3 + 0 + 1 = 16 → The result of the second function penjumlahan(12, 3)</em></p><p><em>13 + 14 + 25 + 1 = 53 → The result of the second function penjumlahan(13,14,25)</em></p><p><strong>4.</strong> <strong>Local and Global Variables in Function</strong></p><p>Inside the function there are local and global variables. Local variables are variables that are presented in the function block itself. So, when the <em>print()</em> command is outside a function or between functions, it will not be defined. And for global variables are variables used outside the function block. So, global variables can be accessed when the <em>print()</em> command is outside the function. The following is an example of the difference between local and global variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*_IV-u_XhnXloK3GqNh2NfQ.png" /></figure><p>The output of the above program is:</p><p><em>10</em></p><p><em>10</em></p><p>In the picture above is an example of a function to distinguish local and global variables. The value of <em>n</em> inside the function is a local variable, while the one outside the function is a global variable. This can be seen from the output with the result 10. Even though in the second function the command<em> print()</em> is inside the function, the variable <em>n</em> will still be defined because the variable <em>n</em> is a global variable. Look at the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*MM5NIZ3YSSgskMPrIVYwaw.png" /></figure><p>The output results in the image above are:</p><p><em>print(n)</em></p><p><em>NameError: name ’n’ is not defined</em></p><p>In the picture above, it can be seen from the output when the function is called and using the <em>print()</em> command the value of <em>n</em> in the function is not defined because the variable <em>n</em> is a local variable that can only be accessed inside the function itself.</p><p><strong>Example problem/case study</strong></p><p>From the presentation of the material above, we can apply it in learning in everyday life. The following is an example of a case study of the list data type that is around us.</p><p>Write a function<strong> is Pythagoras</strong>(a, b, c) that is used to determine whether the pairs a, b, c that are sides of a triangle are Pythagorean triples or not. The function returns a boolean value: True if a, b, c are Pythagorean triples, and False if they are not Pythagorean triples.</p><p>Note: c is the hypotenuse of the triangle.</p><p>To check if the function you created is correct, test it with the following value pairs a, b, c:</p><p><em>1. a = 3, b = 4, c = 5 -&gt; True</em></p><p><em>2. a = 5, b = 9, c = 12-&gt; False</em></p><p><em>3. a = 8, b = 6, c = 10-&gt; True</em></p><p><em>4. a = 7, b = 8, c = 11-&gt; False</em></p><p>From the above problems can be obtained script program as follows.</p><p><em>def isPythagoras(a, b, c):</em></p><p><em>if c*c ==(a*a + b*b):</em></p><p><em>print(True)</em></p><p><em>else:</em></p><p><em>print(False)</em></p><p><em>a= int(input(“a = “))</em></p><p><em>b= int(input(“b = “))</em></p><p><em>c= int(input(“c = “))</em></p><p><em>isPythagoras(a,b,c)</em></p><p>In the script above, it can be explained that we use a def function with the name ‘isPythagoras’ with parameters ‘a,b,c’ can be written as def isPythagoras(a, b, c): which in this function contains the first two conditional statements, the first <em>if c *c == (a*a + b*b):</em> if parameter <em>c</em> is multiplied by parameter <em>c</em>, the value of parameter <em>a</em> is multiplied by parameter <em>a</em>, then parameter <em>b</em> is multiplied by parameter <em>b</em>. And if the number entered is correct then the command <em>print(True)</em> will be executed. And if false, the second conditional statement will be executed and the command <em>print(False)</em> will be executed. Then outside the function itself, we create some variables for example, where these variables are parameters in the function <em>def isPythagoras(a, b, c).</em> This variable is used to input the numbers to be proven whether they are included in the Pythagorean triple or not. Then after that we call the <em>def()</em> function so that the formula contained in the <em>def()</em> function can be used with <em>isPythagoras(a,b,c).</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7304f83682f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DATA LIST TYPE IN PYTHON]]></title>
            <link>https://medium.com/@linanurullaili_90897/data-list-type-in-python-f4310034f3ae?source=rss-a02bb2181160------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4310034f3ae</guid>
            <category><![CDATA[tipe-data]]></category>
            <category><![CDATA[python-list]]></category>
            <category><![CDATA[data-list]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Linanurullaili]]></dc:creator>
            <pubDate>Sun, 26 Dec 2021 07:41:37 GMT</pubDate>
            <atom:updated>2021-12-26T07:41:37.641Z</atom:updated>
            <content:encoded><![CDATA[<p>The list data type belongs to the dynamic data type category. A dynamic data type is a data type used in python to store more than one value in a variable. Dynamic data types consist of several types, namely list data types, set data types, tuple data types, and dictionary data types.</p><p>The list data type is a versatile and ordered data type available in python which is indicated by square brackets and the contents are separated by commas. The contents of the list do not have to have the same data type, but the list can be filled with a string data type or an integer data type. A list can also contain multiple values ​​in a single variable. A simple example for creating a list is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*zTS4lmUoWTn9jPVt6wcDbQ.png" /></figure><p>In the example above is an example of a list with the same data type, namely the integer data type, while below is an example of a list with a different data type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*-1E_h9847Cjw6Fmqm1PYHA.png" /></figure><p><strong>1.</strong> <strong>Access Data In List Python</strong></p><p>In the list we can access the values ​​in it by square brackets along with the index to be accessed. In a list, the index starts at index zero and so on. An example of accessing a value in a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*8CguR2ypMSZyyamfb5Es_Q.png" /></figure><p>In the image above, a list is presented. If we want to access the values ​​in it, for example we use the command <em>“print (myList[0])”</em> then the result of the command is ‘<em>aku</em>’. In the list the index starts from zero to the nth value because in the list there are <em>n</em> values. So we can find out what index the list has depending on the number of <em>n</em> values ​​in the list.</p><p>We can also access multiple values ​​(create a sublist) in the list with square brackets and also the index to which number is accompanied by a colon (:). Example of accessing multiple values ​​in a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*YhTDSTfWvswBceYN5gfGCg.png" /></figure><p>In the picture above there is the command “print (myList[0:7])” which means accessing the list value from index 0 to index 7–1 so index 6, in this case the seventh index is not included. And if you want to access all list you can use print(myList[0:]) command which means you can access list value from index 0 to index<em> n</em> of list.</p><p>We can also find the <em>n</em> index of data in the list using the index() command. The following is an example of how to find the index of <em>n</em> data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*9732ObfmYY2AstZyhe-CoQ.png" /></figure><p>In the image above we can find out what ‘<em>kita</em>’ index is in the list by using the command <em>print(myList.index(‘kita’)).</em> So the result is ‘<em>kita</em>’ data is in the second index.</p><p><strong>2. Arithmetic Operations In Data List Python</strong></p><p>List can also be used on arithmetic operating systems, but in this case the data type used must be the same because it uses the operator (+). So, for example data has an integer value, then <em>list[]+n</em>, where in square brackets is the index value to be accessed and <em>n</em> itself is the number you want to add to the index accessed. And if the data is a string then <em>list[] + ‘str’ </em>inside square brackets is the index value to be accessed and <em>‘str’</em> is what letter to add to the index being accessed. An example of a list in an arithmetic operating system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*xmbqQ2iFs13Hrqz8pZkB7Q.png" /></figure><p>The operation in the image above is the command <em>myList[1] + 2</em>, the first index of the data list above is added to 2, so the result is 6. And in the command <em>myList[3] + ‘Perkenalkan’ + myList[4] + ‘Lina’,</em> the third index is added the word <em>‘Perkenalkan</em>’ then added a fourth index list and added the word <em>‘Lina’</em> then the result is <em>‘hello Perkenalkan my name Lina’</em>.</p><p><strong>3. List Is In A List In Python</strong></p><p>In the list there can also be a list. So, in a list there is also an array of lists and the command is <em>list[][]</em> which in the first square bracket is the index of the list and the second bracket is the index of the sublist. Here is an example in the list there is also a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*iSkQtWRjrRFIXy3_rFFVkg.png" /></figure><p>In the picture above there is the command <em>myList[2],</em> so the result is a list of the two indexes. Then there is the command <em>myList[0] + myList[3]</em> then the result is the sum of index 0 of the list and index 3 of the list. There is also the command myList[2][1] the result is the second index list then in the second index list we look for the number 1 index. That means the <br> number 1 index value of myList[2].</p><p><strong>4. Update Data In Data List Python</strong></p><p>We may also update data from the list. Via <em>list[]=n</em> where in square brackets accesses the index to be updated, while ’n’ is the new data of the updated index. Here is an example of updating data/values ​​from a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*DlteC-si00gQIqIVgWk_MQ.png" /></figure><p>In the picture above the list in the second index when there is a print command the result is still ‘dia’, but when it is updated with the command myList[2]= ‘kita’, the result is [‘aku’, ‘kamu’, ‘kita’].</p><p><strong>5. Delete Values ​​In Data List Python</strong></p><p>In a list we can also remove the values ​​in it by using the commands remove() or del. If you use <em>remove()</em>, then <em>list.remove(n)</em> where <em>n</em> is the data to be deleted. If you use <em>del(),</em> then <em>del list[] </em>where inside the square brackets is the index data to be deleted. Here’s an example of deleting a value in a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*DG6E4CLBfEJNSoeS03e8bA.png" /></figure><p>In the picture above there is the command <em>del myList[3]</em>, the result is that the third index from the list will be deleted. However, we can also use the command<em> remove()</em>, namely with <em>myList.remove(‘kita’)</em> then the value of ‘<em>kita’</em> in the list will be deleted.</p><p><strong>6. Sort List Data Python</strong></p><p>In sorting list data in python we can use commands<em> sort()</em> and and <em>reverse()</em>. If you are using <em>sort()</em> then use the <em>list.sort()</em> method and then use the command<em> print() </em>to update the data. And if you use reverse then <em>list.sort(reverse=True) </em>because the default sort uses sort then followed by reverse because if you directly use reverse then the program results will be an error. After that use the command<em> print()</em> to update the data. The following is an example of sorting a list of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*qIa9SNoQL_daAcpXdLqjtg.png" /></figure><p>In the picture above there is the command <em>‘sort()’</em> which is used to sort data from the earliest alphabetical or smallest number. Then there is the command <em>(reverse=True)</em> which is used to sort from the last alphabetical and largest number. In the picture using the true command because how to use reverse must be accompanied by true then <em>‘print myList’.</em> Sort is the default in sorting a list, namely from the smallest or the earliest.</p><p><strong>7. Adding Values ​​To Data List Python</strong></p><p>In the list we can also add values ​​using the commands<em> append()</em> and <em>insert()</em>. The difference between append and insert is that if <em>append()</em> adds a list value, it will automatically increment at the last index. If <em>insert()</em> inserts in the middle of the list value data. Using the command<em> append()</em>, <em>list.append(n)</em> where <em>n </em>is the data to be appended. While using the command<em> insert()</em>, using <em>list.insert(a,b) </em>where <em>a</em> is the index that will be used to insert the data, while <em>b</em> is the name of the data to be inserted. The following is an example of adding a value to a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*bynvXIlVUGD4CvOW_zQulQ.png" /></figure><p>In the image above, the command <em>append()</em> adds the ‘dia’ data right at the last index. While the command<em> insert()</em> is to insert ‘mereka’ data into index number 1.</p><p><strong>8. Check The Presence Of Data In The List</strong></p><p>In lists we can also check the existence of data in the list with the commands <em>in</em> and <em>not in</em>. The following is an example of checking the existence of data in a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*bQk4dIzZZ8YqM56v4gPboQ.png" /></figure><p>In the picture above we check whether <em>‘Lina’</em> is in the data list or not using the <em>in</em> command and the answer is <em>True</em> (yes). Then we can also see when there is a command <em>‘Lina’</em> that is <em>not in</em> <em>myList</em> then the result of the command is <em>False </em>(No). Why? Because what is meant by not in is whether the data ‘<em>Lina</em>’ is <em>not in myList</em> then the answer must be wrong because the data ‘<em>Lina</em>’ is in the data myList.</p><p><strong>9. Knowing The Amount Of Data In A List Python</strong></p><p>We can also find out the total number of data in the list by using the command <em>len()</em>. The following is an example of how to find out the amount of data in a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*1Auv0aAwgn6ZA4ITn-wfMg.png" /></figure><p>In the picture above, a list is presented and we want to know how much data is in it, so we use the command <em>len(),</em> so the result of a lot of data in the list is 5.</p><p><strong>Example problem/case study</strong></p><p>From the presentation of the material above, we can apply it in learning in everyday life. The following is an example of a case study of the list data type that is around us.</p><p>→ Write a Python program that accepts <em>n</em> integers as input. In this case, the user is asked to first determine the value of <em>n </em>before entering an integer. Then the program can display all the integers in descending order from large to small (descending). Then the python program script of the problem is.</p><p>try:</p><p>banyak = int(input(‘Berapa banyak bilangan yang ingin dimasukan: ‘))</p><p>bil = []</p><p>for i in range(banyak):</p><p>angka = int(input(‘Masukkan Angka Ke-’ + str(i+1) + ‘: ‘))</p><p>bil = bil + [angka]</p><p>bil.sort(reverse=True)</p><p>print(‘Angka yang anda masukkan adalah’, bil)</p><p>except ValueError:</p><p>print(‘INPUT BUKAN ANGKA!!’)</p><p>From the program script above, it can be explained that we use the exception heading function if if we input a number that is not an integer it will output ‘maaf input bukan angka’. It contains a ‘banyak’ variable to input the number of numbers you want to enter. Then the variable ‘bil’ for example a list. We use looping to do the iteration according to the number of numbers entered in the ‘banyak’ variable in which there is a new variable, namely ‘angka’, to input integers according to the number of numbers desired by the ‘banyak’ variable. Then the variable ‘bil’ is the sum of the variable ‘bil’ with a number variable in the form of a list, namely bil = bil + [angka]. Then outside the loop, we sort the list that was made earlier from the largest to the smallest. Followed by the command <em>print ()</em> and call the variable ‘bil’ whose contents already contain the list earlier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4310034f3ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>