{"id":4590,"date":"2015-04-25T14:55:55","date_gmt":"2015-04-25T06:55:55","guid":{"rendered":"http:\/\/rmohan.com\/?p=4590"},"modified":"2015-04-26T12:26:35","modified_gmt":"2015-04-26T04:26:35","slug":"python-tutorial","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4590","title":{"rendered":"Python Tutorial"},"content":{"rendered":"<p><strong>\u00a0Data Type Conversion<\/strong><\/p>\n<p>a) int(55.89)<\/p>\n<p>b) float(36)<\/p>\n<p>my_string=str(9500)<\/p>\n<p><strong>Tuple <\/strong><br \/>\n<strong>\u00a0<\/strong><br \/>\n&gt;&gt;&gt; tuple(&#8220;This is a string.&#8221;)<br \/>\n(&#8216;T&#8217;, &#8216;h&#8217;, &#8216;i&#8217;, &#8216;s&#8217;, &#8216; &#8216;, &#8216;i&#8217;, &#8216;s&#8217;, &#8216; &#8216;, &#8216;a&#8217;, &#8216; &#8216;, &#8216;s&#8217;, &#8216;t&#8217;, &#8216;r&#8217;, &#8216;i&#8217;, &#8216;n&#8217;, &#8216;g&#8217;, &#8216;.&#8217;)<br \/>\n&gt;&gt;&gt;<\/p>\n<p>list(&#8220;This will be a list&#8221;)<\/p>\n<p>&gt;&gt;&gt; list(&#8220;This will be a list&#8221;)<br \/>\n[&#8216;T&#8217;, &#8216;h&#8217;, &#8216;i&#8217;, &#8216;s&#8217;, &#8216; &#8216;, &#8216;w&#8217;, &#8216;i&#8217;, &#8216;l&#8217;, &#8216;l&#8217;, &#8216; &#8216;, &#8216;b&#8217;, &#8216;e&#8217;, &#8216; &#8216;, &#8216;a&#8217;, &#8216; &#8216;, &#8216;l&#8217;, &#8216;i&#8217;, &#8216;s&#8217;, &#8216;t&#8217;]<\/p>\n<p>chr(65)<\/p>\n<p>ord(&#8216;a&#8217;)<\/p>\n<p>hex(4500)<\/p>\n<p>bin(42)<br \/>\n================================================================================<\/p>\n<p><strong>Arithmetic &amp; Comparison Operators<\/strong><\/p>\n<p><strong>7 kind of operators\u00a0 \u00a0<\/strong><\/p>\n<p>Arithmetic = + , &#8211; , \/ , % , **<\/p>\n<p>a=10<br \/>\nb=15<br \/>\na+b<\/p>\n<p>&gt;&gt;&gt; a=10<br \/>\n&gt;&gt;&gt; b=10<br \/>\n&gt;&gt;&gt; a+b<br \/>\n20<\/p>\n<p>a*b<\/p>\n<p>comparison operator = a==b\u00a0\u00a0 check a equal to b<br \/>\na!=b , a&gt;b , a&lt;b , a&lt;=b ,\u00a0 a&gt;=b<\/p>\n<p>&gt;&gt;&gt; a=10<br \/>\n&gt;&gt;&gt; b=10<br \/>\n&gt;&gt;&gt; a+b<br \/>\n20<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; a==b<br \/>\nTrue<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; a=15<br \/>\n&gt;&gt;&gt; b=10<br \/>\n&gt;&gt;&gt; a==b<br \/>\nFalse<br \/>\n&gt;&gt;&gt;<\/p>\n<p><strong>Bitwise &amp; Logical Operators<\/strong><\/p>\n<p>&gt;&gt;&gt; a=15<br \/>\n&gt;&gt;&gt; b=20<br \/>\n&gt;&gt;&gt; bin(a)<br \/>\n&#8216;0b1111&#8217;<br \/>\n&gt;&gt;&gt; bin(b)<br \/>\n&#8216;0b10100&#8217;<br \/>\n&gt;&gt;&gt; bin(a&amp;b)<br \/>\n&gt;&gt;&gt; bin(a&amp;b)<br \/>\n&#8216;0b100&#8217;<br \/>\n&gt;&gt;&gt; bin(a|b)<br \/>\n&#8216;0b11111&#8217;<br \/>\n&gt;&gt;&gt; bin(a^b)<br \/>\n&#8216;0b11011&#8217;<\/p>\n<p><strong>AND Operation <\/strong><\/p>\n<p>a=True<br \/>\nb=False<br \/>\na\u00a0 and b<br \/>\nFalse<\/p>\n<p>a or b<br \/>\nTrue<\/p>\n<p>not a<br \/>\nFalse<\/p>\n<p>not b<br \/>\nTrue<\/p>\n<p>===============================================================================<br \/>\n<strong>Membership &amp; Identity Operators<\/strong><\/p>\n<p>Membership Operators<br \/>\nstr1=&#8221;I have a lazy dog&#8221;<br \/>\n&gt;&gt;&gt; str1=&#8221;I have a lazy dog&#8221;<br \/>\n&gt;&gt;&gt; str1<br \/>\n&#8216;I have a lazy dog&#8217;<br \/>\n&gt;&gt;&gt; &#8220;dog&#8221; in str1<br \/>\nTrue<\/p>\n<p>&gt;&gt;&gt; mylist=[1,3,19,32,48,77]<br \/>\n&gt;&gt;&gt; 65 in mylist<br \/>\nFalse<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; 19 in mylist<br \/>\nTrue<br \/>\n&gt;&gt;&gt;<\/p>\n<p><strong>Identity Operators<\/strong><\/p>\n<p>&gt;&gt;&gt; a = 43<br \/>\n&gt;&gt;&gt; b= &#8217;43&#8217;<br \/>\n&gt;&gt;&gt; a is b<br \/>\nFalse<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; c=42<br \/>\n&gt;&gt;&gt; a is c<br \/>\nFalse<br \/>\n&gt;&gt;&gt; c=43<br \/>\n&gt;&gt;&gt; a is c<br \/>\nTrue<br \/>\n&gt;&gt;&gt;<\/p>\n<p>===============================================================================<br \/>\n<strong>Operator Precedence<\/strong><\/p>\n<p>Multiple operator proceeds first<br \/>\n&gt;&gt;&gt;5+4*2<br \/>\n13<\/p>\n<p>&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; (5+4)*2<br \/>\n18<br \/>\n&gt;&gt;&gt;<\/p>\n<p>=====================================================================================<br \/>\n<strong>The IF statement<\/strong><\/p>\n<p>&gt;&gt;&gt; myvar=50<br \/>\n&gt;&gt;&gt; if myvar&lt;100:<br \/>\nprint(&#8220;You are 100 %&#8221;)<\/p>\n<p>You are 100 %<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; myvar=150<br \/>\n&gt;&gt;&gt; if myvar&lt;100:<br \/>\nprint(&#8220;You are 100 %&#8221;)<\/p>\n<p>&gt;&gt;&gt;<br \/>\n=====================================================================================<br \/>\n<strong>The ELSE Statement<\/strong><\/p>\n<p>&gt;&gt;&gt; myvar=50<br \/>\n&gt;&gt;&gt; if myvar&lt;100:<br \/>\nprint(&#8220;your are short of 100 %&#8221;)<br \/>\nelse:<br \/>\nprint (&#8220;your in 100 %&#8221;)<br \/>\nprint (&#8220;thank you&#8221;)<\/p>\n<p>your are short of 100 %<br \/>\n&gt;&gt;&gt;<\/p>\n<p>============================================================================<br \/>\n<strong>The ELIF Statement<\/strong><\/p>\n<p>&gt;&gt;&gt; sp=1500<br \/>\n&gt;&gt;&gt; cp=1200<br \/>\n&gt;&gt;&gt; if (sp&gt;cp):<br \/>\nprint(&#8220;congrats!&#8221;)<br \/>\nprint(&#8220;You&#8217;ve made profit of &#8220;, sp-cp,&#8221;bucks&#8221;)<br \/>\nelif (cp&gt;sp):<br \/>\nprint(&#8220;oops!&#8221;)<br \/>\nprint(&#8220;You ve made a loss of &#8220;, cp-sp,&#8221;bucks&#8221;)<br \/>\nelse:<br \/>\nprint(&#8220;You did or lose money&#8221;)<\/p>\n<p>congrats!<br \/>\nYou&#8217;ve made profit of\u00a0 300 bucks<\/p>\n<p>&gt;&gt;&gt; sp=1500<br \/>\n&gt;&gt;&gt; cp=1500<br \/>\n&gt;&gt;&gt; if (sp&gt;cp):<br \/>\nprint(&#8220;congrats!&#8221;)<br \/>\nprint(&#8220;You&#8217;ve made profit of &#8220;, sp-cp,&#8221;bucks&#8221;)<br \/>\nelif (cp&gt;sp):<br \/>\nprint(&#8220;oops!&#8221;)<br \/>\nprint(&#8220;You ve made a loss of &#8220;, cp-sp,&#8221;bucks&#8221;)<br \/>\nelse:<br \/>\nprint(&#8220;You did or lose money&#8221;)<\/p>\n<p>You did or lose money<\/p>\n<p>============================================================================<br \/>\n<strong>Nested IF-ELSE<\/strong><\/p>\n<p>&gt;&gt;&gt; char=input()<br \/>\nif ord(char)&gt;=65\u00a0 and ord(char)&lt;=90:<br \/>\nprint(&#8220;You entered an uper case alpabet.&#8221;)<br \/>\nif char in [&#8216;A&#8217;,&#8217;E&#8217;,&#8217;I&#8217;,&#8217;O&#8217;,&#8217;U&#8217;]:<br \/>\nprint(&#8220;You entered a Vowel.&#8221;)<br \/>\nelse:<br \/>\nprint(&#8220;You entered a consonant.&#8221;)<br \/>\nelif ord(char)&gt;=97\u00a0 and ord(char)&lt;=122:<br \/>\nprint(&#8220;You entered a lower case alaphabet.&#8221;)<br \/>\nif char in [&#8216;a&#8217;,&#8217;e&#8217;,&#8217;i&#8217;,&#8217;o&#8217;,&#8217;u&#8217;]:<br \/>\nprint(&#8220;you entered a vowel.&#8221;)<br \/>\nelse:<br \/>\nprint(&#8220;You entered a consonant.&#8221;)<br \/>\nelse:<br \/>\nprint(&#8220;you did not enter an alphabet.&#8221;)<\/p>\n<p>============================================================================<\/p>\n<p><strong>The WHILE Loop<\/strong><\/p>\n<p>&gt;&gt;&gt; var=1<br \/>\n&gt;&gt;&gt; while(var&lt;=10):<br \/>\nprint(&#8220;Hi! i am&#8221;, var)<br \/>\nvar=var+1<br \/>\nprint(&#8220;good bye!&#8221;)<\/p>\n<p>var=1<br \/>\n&gt;&gt;&gt; while(var&lt;=10):<br \/>\nprint(&#8220;Hi! i am&#8221;, var)<br \/>\nvar=var+1<br \/>\nprint(&#8220;hello&#8221;)<br \/>\nprint(&#8220;good bye!&#8221;)<\/p>\n<p>============================================================================<br \/>\n<strong>\u00a0\u00a0 \u00a0<\/strong><br \/>\n<strong>The FOR Loop<\/strong><\/p>\n<p>&gt;&gt;&gt; count=0<br \/>\n&gt;&gt;&gt; print(&#8220;Enter your name:&#8221;)<br \/>\nEnter your name:<br \/>\n&gt;&gt;&gt; name=input()<br \/>\n&gt;&gt;&gt; for letter in name:<br \/>\nif (letter in [&#8216;A&#8217;,&#8217;E&#8217;,&#8217;I&#8217;,&#8217;O&#8217;,&#8217;U&#8217;,&#8217;a&#8217;,&#8217;e&#8217;,&#8217;i&#8217;,&#8217;o&#8217;,&#8217;u&#8217;]):<br \/>\ncount=count+1<br \/>\nprint(&#8220;You have&#8221;,count, &#8220;Vowels in your name.&#8221;)<\/p>\n<p>You have 1 Vowels in your name.<br \/>\nYou have 2 Vowels in your name.<br \/>\nYou have 3 Vowels in your name.<br \/>\nYou have 4 Vowels in your name.<br \/>\nYou have 5 Vowels in your name.<br \/>\nYou have 6 Vowels in your name.<br \/>\nYou have 7 Vowels in your name.<br \/>\nYou have 8 Vowels in your name.<br \/>\nYou have 9 Vowels in your name.<br \/>\n&gt;&gt;&gt;<\/p>\n<p>============================================================================<br \/>\n<strong>The Break Statement<\/strong><\/p>\n<p>var=1<br \/>\nwhile(var&lt;=15):<br \/>\nprint(var)<br \/>\nvar=var+1<br \/>\nprint(&#8220;Good bye&#8221;)<\/p>\n<p>1<br \/>\nGood bye<br \/>\n2<br \/>\nGood bye<br \/>\n3<br \/>\nGood bye<br \/>\n4<br \/>\nGood bye<br \/>\n5<br \/>\nGood bye<br \/>\n6<br \/>\nGood bye<br \/>\n7<br \/>\nGood bye<br \/>\n8<br \/>\nGood bye<br \/>\n9<br \/>\nGood bye<br \/>\n10<br \/>\nGood bye<br \/>\n11<br \/>\nGood bye<br \/>\n12<br \/>\nGood bye<br \/>\n13<br \/>\nGood bye<br \/>\n14<br \/>\nGood bye<br \/>\n15<br \/>\nGood bye<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; var=1<br \/>\n&gt;&gt;&gt; while(var&lt;=15):<br \/>\nif(var==10):<br \/>\nbreak<br \/>\nprint(var)<br \/>\nvar=var+1<br \/>\nprint(&#8220;Good bye&#8221;)<\/p>\n<p>1<br \/>\nGood bye<br \/>\n2<br \/>\nGood bye<br \/>\n3<br \/>\nGood bye<br \/>\n4<br \/>\nGood bye<br \/>\n5<br \/>\nGood bye<br \/>\n6<br \/>\nGood bye<br \/>\n7<br \/>\nGood bye<br \/>\n8<br \/>\nGood bye<br \/>\n9<br \/>\nGood bye<br \/>\n============================================================================<\/p>\n<p>Application of Break Statement<\/p>\n<p>while True:<br \/>\nprint(&#8220;Enter\u00a0 a digit:&#8221;)<br \/>\nnum=input()<br \/>\nvar=str(num)<br \/>\nif(ord(var) in range(48,58)):<br \/>\nbreak<br \/>\nprint(&#8220;You are very obedient!&#8221;)<\/p>\n<p>============================================================================<br \/>\nNested Loops<\/p>\n<p>for var1 in range(2,101):<br \/>\nflag=True<br \/>\nfor var2 in range(2,var1-1):<br \/>\nif(var1%var2==0):<br \/>\nprint(var1,&#8221;is not a prime number&#8221;)<br \/>\nflag=False<br \/>\nbreak<br \/>\nif flag:<br \/>\nprint(var1, &#8220;is a prime number.&#8221;)<\/p>\n<p>============================================================================<\/p>\n<p><strong>The Continue Statement<\/strong><\/p>\n<p>for var in range(1,16):<br \/>\nif(var in range(9,14)):<br \/>\ncontinue<br \/>\nelse:<br \/>\nprint(var)<\/p>\n<p>print(&#8220;Enter a string:&#8221;)<br \/>\nEnter a string:<br \/>\nvar=input()<br \/>\nfor letter in var:<br \/>\nif(leter==&#8217; &#8216;):<br \/>\ncontinue<br \/>\nelse:<br \/>\nprint(letter)<br \/>\n========================================================================<br \/>\n<strong>Numeric Functions<\/strong><\/p>\n<p>abs(5)<br \/>\nabs(-5)<\/p>\n<p>import math<br \/>\nmath.ceil(35.74)<\/p>\n<p>&gt;&gt;&gt; import math<br \/>\n&gt;&gt;&gt; math.ceil(35.74)<br \/>\n36<br \/>\n&gt;&gt;&gt; math.e<br \/>\n2.718281828459045<br \/>\n&gt;&gt;&gt; math.exp(7)<br \/>\n1096.6331584284585<br \/>\n&gt;&gt;&gt; math.e**7<br \/>\n1096.6331584284583<br \/>\n&gt;&gt;&gt; math.floor(16.94)<br \/>\n16<br \/>\n&gt;&gt;&gt; math.floor(-16.94)<br \/>\n-17<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; math.sqrt(25)<br \/>\n5.0<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; math.log(5)<br \/>\n1.6094379124341003<br \/>\n&gt;&gt;&gt; math.log(math.e)<br \/>\n1.0<br \/>\n&gt;&gt;&gt; &gt;&gt;&gt; math.log10(10)<br \/>\n1.0<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; max(10,15,20,45-18)<br \/>\n27<br \/>\n&gt;&gt;&gt; max(10,15,20,45-18)<br \/>\n27<br \/>\n&gt;&gt;&gt; min(11,19,17,6-213)<br \/>\n-207<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; round(17.234234)<br \/>\n17<\/p>\n<p>&gt;&gt;&gt; math.modf(11.971)<br \/>\n(0.9710000000000001, 11.0)<\/p>\n<p>&gt;&gt;&gt; math.pow(4,2)<br \/>\n16.0<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; math.hypot(5,12)<br \/>\n13.0<br \/>\n&gt;&gt;&gt; math.hypot(3,14)<br \/>\n14.317821063276352<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; math.degrees(math.pi)<br \/>\n180.0<br \/>\n&gt;&gt;&gt; math.degrees(-4)<br \/>\n-229.1831180523293<br \/>\n&gt;&gt;&gt; math.radians(-229.18311)<br \/>\n-3.9999998594603414<br \/>\n&gt;&gt;&gt;<\/p>\n<p>========================================================================<\/p>\n<h1 class=\"yt watch-title-container\"><span id=\"eow-title\" class=\"watch-title \" dir=\"ltr\" title=\"Python Programming Tutorial - 26: String Functions (Part-1)\">String Functions<span class=\"Apple-converted-space\">\u00a0<\/span><\/span><\/h1>\n<p>&nbsp;<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;hey, how are you?&#8221;<br \/>\n&gt;&gt;&gt; str1.capitalize()<br \/>\n&#8216;Hey, how are you?&#8217;<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;&#8221;&#8221;tom is a good guy<br \/>\ntom is hard working<br \/>\ntom is honest<br \/>\ntom is team player<br \/>\ntom work out&#8221;&#8221;&#8221;<br \/>\n&gt;&gt;&gt; str1<br \/>\n&#8216;tom is a good guy\\ntom is hard working\\ntom is honest\\ntom is team player\\ntom work out&#8217;<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; str1.count(&#8216;tom&#8217;)<br \/>\n5<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;rmohan.com&#8221;<br \/>\n&gt;&gt;&gt; str1.endswith(&#8216;.org&#8217;)<br \/>\nFalse<br \/>\n&gt;&gt;&gt; str1.endswith(&#8216;.com&#8217;)<br \/>\nTrue<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;catch me if you can&#8221;<br \/>\n&gt;&gt;&gt; str1.find(&#8216;you&#8217;)<br \/>\n12<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;hey, how are you?&#8221;<br \/>\n&gt;&gt;&gt; str1=&#8221;&#8221;&#8221;tom is a good guy<br \/>\ntom is hard working<br \/>\ntom is honest<br \/>\ntom is team player<br \/>\ntom work out&#8221;&#8221;&#8221;<br \/>\n&gt;&gt;&gt; str1.count(&#8216;tom&#8217;)<br \/>\n5<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; str1=&#8221;rmohan.com&#8221;<br \/>\n&gt;&gt;&gt; str1.endswith(&#8216;.org&#8217;)<br \/>\nFalse<br \/>\n&gt;&gt;&gt; str1.endswith(&#8216;.com&#8217;)<br \/>\nTrue<br \/>\n&gt;&gt;&gt; str1.endswith(&#8216;.com&#8217;)<br \/>\nTrue<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;Hello World&#8221;<br \/>\n&gt;&gt;&gt; str1.islower()<br \/>\nFalse<br \/>\n&gt;&gt;&gt; str1=&#8221;hello world&#8221;<br \/>\n&gt;&gt;&gt; str1.islower()<br \/>\nTrue<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;!!!!!!what&#8217;s up dudes?&#8221;<br \/>\n&gt;&gt;&gt; str1.lstrip(&#8216;!&#8217;)<br \/>\n&#8220;what&#8217;s up dudes?&#8221;<br \/>\n&gt;&gt;&gt; str1=&#8221;!!!!!!what&#8217;s up dudes?&#8221;<br \/>\n&gt;&gt;&gt; str1.lstrip(&#8216;!&#8217;)<br \/>\n&#8220;what&#8217;s up dudes?&#8221;<br \/>\n&gt;&gt;&gt; str1=&#8221;This is so cool!!!!!!&#8221;<br \/>\n&gt;<br \/>\n&gt;&gt;&gt; str1.rstrip(&#8216;!&#8217;)<br \/>\n&#8216;This is so cool&#8217;<br \/>\n&gt;&gt;&gt; str1=&#8221;This is so cool!!!!!!&#8221;<br \/>\n&gt;&gt;&gt; str1.rstrip(&#8216;!&#8217;)<br \/>\n&#8216;This is so cool&#8217;<br \/>\n&gt;&gt;&gt; str1.upper()<br \/>\n&#8216;THIS IS SO COOL!!!!!!&#8217;<\/p>\n<p>&nbsp;<\/p>\n<p>&gt;&gt;&gt; str=&#8221;I once had a fox&#8221;<br \/>\n&gt;&gt;&gt; str1.replace(&#8216;fox&#8217;,&#8217;lion&#8217;)<br \/>\n&#8216;This is so cool!!!!!!&#8217;<br \/>\n&gt;&gt;&gt; str1<br \/>\n&#8216;This is so cool!!!!!!&#8217;<br \/>\n&gt;&gt;&gt; str1=&#8221;I once had a fox&#8221;<br \/>\n&gt;&gt;&gt; str1.replace(&#8216;fox&#8217;,&#8217;lion&#8217;)<br \/>\n&#8216;I once had a lion&#8217;<br \/>\n&gt;&gt;&gt; str1=&#8221;I once had a fox&#8221;<br \/>\n&gt;&gt;&gt; str1.replace(&#8216;fox&#8217;,&#8217;lion&#8217;)<br \/>\n&#8216;I once had a lion&#8217;<br \/>\n&gt;&gt;&gt; str1<br \/>\n&#8216;I once had a fox&#8217;<br \/>\n&gt;&gt;&gt; str1=&#8221;Tom cuise&#8221;<br \/>\n&gt;&gt;&gt; str1.split()<br \/>\n[&#8216;Tom&#8217;, &#8216;cuise&#8217;]<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; str1=&#8221;########GOOD MORNING########&#8221;<br \/>\n&gt;&gt;&gt; str1.strip(&#8216;#&#8217;)<br \/>\n&#8216;GOOD MORNING&#8217;<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; str1=&#8221;I LOVE python&#8221;<br \/>\n&gt;&gt;&gt; str1.swapcase()<br \/>\n&#8216;i love PYTHON&#8217;<br \/>\n&gt;&gt;&gt; str1.swapcase()<br \/>\n&#8216;i love PYTHON&#8217;<br \/>\n&gt;&gt;&gt; str1.title()<br \/>\n&#8216;I Love Python&#8217;<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&nbsp;<\/p>\n<h1 class=\"yt watch-title-container\"><span id=\"eow-title\" class=\"watch-title \" dir=\"ltr\" title=\"Python Programming Tutorial - 30: List Functions (Part-2)\">List Functions<span class=\"Apple-converted-space\">\u00a0<\/span><\/span><\/h1>\n<p>&gt;&gt;&gt; mylist=[1,3,5,9,4]<br \/>\n&gt;&gt;&gt; len(mylist)<br \/>\n5<br \/>\n&gt;&gt;&gt; max(mylist)<br \/>\n9<br \/>\n&gt;&gt;&gt; min(mylist)<br \/>\n1<br \/>\n&gt;&gt;&gt; mylist=[3,3,3,3,3,1,1,5,5,5,7,7,7,7,9,9]<br \/>\n&gt;&gt;&gt; mylist.count(7)<br \/>\n4<br \/>\n&gt;&gt;&gt; mylist.append(8)<br \/>\n&gt;&gt;&gt; mylist<br \/>\n[3, 3, 3, 3, 3, 1, 1, 5, 5, 5, 7, 7, 7, 7, 9, 9, 8]<br \/>\n&gt;&gt;&gt; mylist.append(8)<br \/>\n&gt;&gt;&gt; mylist<br \/>\n[3, 3, 3, 3, 3, 1, 1, 5, 5, 5, 7, 7, 7, 7, 9, 9, 8, 8]<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; mylist=[4,1,9,3,7,2]<br \/>\n&gt;&gt;&gt; mylist.insert(5,6)<br \/>\n&gt;&gt;&gt; mylist<br \/>\n[4, 1, 9, 3, 7, 6, 2]<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; mylist=[4,1,9,3,7,2]<br \/>\n&gt;&gt;&gt; mylist.insert(5,6)<br \/>\n&gt;&gt;&gt; mylist<br \/>\n[4, 1, 9, 3, 7, 6, 2]<br \/>\n&gt;&gt;&gt; mylist.remove(9)<br \/>\n&gt;&gt;&gt; mylist<br \/>\n[4, 1, 3, 7, 6, 2]<br \/>\n&gt;&gt;&gt; mylist.reverse()<br \/>\n&gt;&gt;&gt; mylist<br \/>\n[2, 6, 7, 3, 1, 4]<br \/>\n&gt;&gt;&gt; mylist.sort()<br \/>\n&gt;&gt;&gt; mylist<br \/>\n[1, 2, 3, 4, 6, 7]<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>===========================================================================<\/p>\n<h1 class=\"yt watch-title-container\"><span id=\"eow-title\" class=\"watch-title \" dir=\"ltr\" title=\"Python - Reading Specific Lines of a Text File - Linux\">Reading Specific Lines\u00a0 Text File<\/span><\/h1>\n<p>cat file.txt<br \/>\nline 1<br \/>\nline 2<br \/>\nline 3<br \/>\nline 4<br \/>\nline 5<\/p>\n<p>#!\/usr\/bin\/env python<\/p>\n<p>f = open(&#8220;file.txt&#8221;)<br \/>\nfor x, line in enumerate(f):<br \/>\nif x==3:<br \/>\nprint line<br \/>\nf.close()<\/p>\n<p>&nbsp;<\/p>\n<p>#!\/usr\/bin\/env python<\/p>\n<p>f = open(&#8220;file.txt&#8221;)<br \/>\nfor x, line in enumerate(f):<br \/>\nif x==3:<br \/>\nprint line<br \/>\nelif x ==2:<br \/>\nprint line<br \/>\nf.close()<\/p>\n<p>&nbsp;<\/p>\n<p>Reading from a text file<\/p>\n<p>&gt;&gt;&gt; infile = open(&#8220;test.txt&#8221;)<br \/>\n&gt;&gt;&gt; dataline = infile.read()<br \/>\n&gt;&gt;&gt; dataline<br \/>\n&#8216;Hello world\\nTest1&#8217;<br \/>\n&gt;&gt;&gt; dataline.split()<br \/>\n[&#8216;Hello&#8217;, &#8216;world&#8217;, &#8216;Test1&#8217;]<br \/>\n&gt;&gt;&gt;<\/p>\n<p>======================================================================<\/p>\n<h1 class=\"yt watch-title-container\"><span id=\"eow-title\" class=\"watch-title \" dir=\"ltr\" title=\"Python Programming Tutorial - 31: Tuple Functions\">Tuple Functions<\/span><\/h1>\n<p>&gt;&gt;&gt; mytuple=(1,2,&#8217;lamb&#8217;,&#8217;apple&#8217;,7)<br \/>\n&gt;&gt;&gt; len(mytuple)<br \/>\n5<br \/>\n&gt;&gt;&gt; mytuple=(78,84,112,-91,43,221)<br \/>\n&gt;&gt;&gt; max(mytuple)<br \/>\n221<br \/>\n&gt;&gt;&gt; min(mytuple)<br \/>\n-91<br \/>\n~<\/p>\n<h1 class=\"yt watch-title-container\"><span id=\"eow-title\" class=\"watch-title \" dir=\"ltr\" title=\"Python Programming Tutorial - 32: Dictionary Functions\">Dictionary Functions<\/span><\/h1>\n<p>&gt;&gt; movies={1994: &#8216;Pulp Fiction&#8217; , 1997: &#8216;Seven&#8217;,2000: &#8216;Cast Away&#8217; ,2006: &#8216;Blood Diamond&#8217;}<br \/>\n&gt;&gt;&gt; movies.keys()<br \/>\ndict_keys([2000, 1994, 1997, 2006])<br \/>\n&gt;&gt;&gt; movies.values()<br \/>\ndict_values([&#8216;Cast Away&#8217;, &#8216;Pulp Fiction&#8217;, &#8216;Seven&#8217;, &#8216;Blood Diamond&#8217;])<br \/>\n&gt;&gt;&gt; new={1972:&#8221;The GodFather&#8221;,1980:&#8221;Raging Bull&#8221;,2004:&#8221;The Aviator&#8221;}<br \/>\n&gt;&gt;&gt; new<br \/>\n{1980: &#8216;Raging Bull&#8217;, 1972: &#8216;The GodFather&#8217;, 2004: &#8216;The Aviator&#8217;}<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&gt;&gt;&gt; movies.update(new)<br \/>\n&gt;&gt;&gt; movies<br \/>\n{2000: &#8216;Cast Away&#8217;, 1972: &#8216;The GodFather&#8217;, 2006: &#8216;Blood Diamond&#8217;, 2004: &#8216;The Aviator&#8217;, 1994: &#8216;Pulp Fiction&#8217;, 1980: &#8216;Raging Bull&#8217;, 1997: &#8216;Seven&#8217;}<br \/>\n&gt;&gt;&gt; movies.clear()<br \/>\n&gt;&gt;&gt; movies<br \/>\n{}<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p> Data Type Conversion<\/p>\n<p>a) int(55.89)<\/p>\n<p>b) float(36)<\/p>\n<p>my_string=str(9500)<\/p>\n<p>Tuple &gt;&gt;&gt; tuple(&#8220;This is a string.&#8221;) (&#8216;T&#8217;, &#8216;h&#8217;, &#8216;i&#8217;, &#8216;s&#8217;, &#8216; &#8216;, &#8216;i&#8217;, &#8216;s&#8217;, &#8216; &#8216;, &#8216;a&#8217;, &#8216; &#8216;, &#8216;s&#8217;, &#8216;t&#8217;, &#8216;r&#8217;, &#8216;i&#8217;, &#8216;n&#8217;, &#8216;g&#8217;, &#8216;.&#8217;) &gt;&gt;&gt;<\/p>\n<p>list(&#8220;This will be a list&#8221;)<\/p>\n<p>&gt;&gt;&gt; list(&#8220;This will be a list&#8221;) [&#8216;T&#8217;, &#8216;h&#8217;, &#8216;i&#8217;, &#8216;s&#8217;, &#8216; &#8216;, &#8216;w&#8217;, &#8216;i&#8217;, [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4590"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4590"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4590\/revisions"}],"predecessor-version":[{"id":4594,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4590\/revisions\/4594"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}