<p><font color="#777777" face="Helvetica Neue, Helvetica, Arial, sans-serif"><span style="font-size: 18px;"><b>There are lots of python tutorials over the internet and python code is self explanatory. So I am thinking to build a python cheat-sheet&nbsp;which may help for revising knowledge over python.</b></span></font></p><blockquote class="blockquote"><h2 style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 1.1; color: rgb(119, 119, 119); margin-top: 20px; margin-bottom: 10px; font-size: 30px;">String</h2></blockquote><pre><pre style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(241, 241, 241); border: 1px solid rgb(204, 204, 204); border-radius: 4px;"><code style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 0px; background-color: transparent; border-radius: 0px; white-space: pre-wrap;">string1 = "Toptechschool" # Single or double quote , assigning value to a string variable named string1 print(string1) # Output Toptechschool string2 = ".com" my_url = string1+''+string2 print(my_url) # Output Toptechschool.com print(my_url[0])# Output T print(my_url[4]) # Output e , indexing start from 0 print(my_url[0:4]) # Output Topt , [inclusive,exclusive] ,print from index 0 #to index 3</code></pre></pre><p></p><h2 style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 1.1; color: rgb(119, 119, 119); margin-top: 20px; margin-bottom: 10px; font-size: 30px;">Set</h2><blockquote style="text-align: left;" class="blockquote"><p><span style="color: rgb(119, 119, 119); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 17.5px;">Sets are unordered collections of unique objects. There are two types of sets. * sets (mutable,new elements can be added) * frozenset (immutable, new elements can't be added)</span></p></blockquote><pre><pre style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(241, 241, 241); border: 1px solid rgb(204, 204, 204); border-radius: 4px;"><code style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 0px; background-color: transparent; border-radius: 0px; white-space: pre-wrap;">country = {'Australia','Canada','England','Canada','Australia'} print(country) # {'England', 'Canada', 'Australia'} var = set('toptechschool') print(var) # {'c', 'e', 's', 't', 'h', 'l', 'o', 'p'} var.add('c') # c does not added var.add('x') # x added</code></pre></pre><blockquote style="text-align: left;" class="blockquote"><blockquote class="blockquote"><span style="font-size: 24px;"></span></blockquote><h2 style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 1.1; color: rgb(119, 119, 119); margin-top: 20px; margin-bottom: 10px; font-size: 30px;">List</h2><p style="margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: rgb(119, 119, 119); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 17.5px;">A list contains items separated by commas and enclosed within square brackets [].lists are almost similar to arrays in C.</p></blockquote><pre><pre style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(241, 241, 241); border: 1px solid rgb(204, 204, 204); border-radius: 4px;"><code style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 0px; background-color: transparent; border-radius: 0px; white-space: pre-wrap;">list1 = [123,'abcd',10.2,'d'] # mixed data types in a list bikes = ['trek', 'redline', 'giant'] # Making a list of 3 items first_bike = bikes[0] # trek last_bike = bikes[-1] # giant copy_of_bikes = bikes[:] #copying a list bikes = [] # empty list bikes.append('trek') #adding list item bikes.append('redline') #adding list item bikes.append('giant') #adding list item del bikes[1] # removing items by index bikes.remove('trek') #removing items by value for bike in bikes: #loop through all elements in list print(bike) squares = [] # empty list for x in range(1, 11): #loop through 1 to 10 squares.append(x**2) squares = [x**2 for x in range(1, 11)] #list comprehension : doing the previous work in one line len(squares) #length of list finishers = ['sam', 'bob', 'ada', 'bea'] first_two = finishers[:2] # getting the first two item, [inclusive,exclusive] numbers = [1,4,123,32,5,4] numbers.sort() # sorting a list numbers.reverse() # reversing a list</code></pre></pre><h2 style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 1.1; color: rgb(119, 119, 119); margin-top: 20px; margin-bottom: 10px; font-size: 30px;">Dictionary<br></h2><p style="margin-right: 0px; margin-bottom: 0px; margin-left: 0px; color: rgb(119, 119, 119); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 17.5px;">Dictionaries store connections between pieces of information. Each item in a dictionary is a key-value pair.</p><pre style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(241, 241, 241); border: 1px solid rgb(204, 204, 204); border-radius: 4px;"><code style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 0px; background-color: transparent; border-radius: 0px; white-space: pre-wrap;">dic={'name':'red','age':10} print(dic['name']) # red dic['height'] = 5.9 # adding new key with a value del dic['height'] # deleting dictionary print(dic) # {'name': 'red', 'age': 10}</code></pre><p></p>

About the author

Tarek

My goal is to excel in advanced computer applications in order to contribute to the organization as well as to self-efficacy and communication skills to build my career. I like programming challenges to solve under pressure.