An introduction to Python programming. It covers the syntax for commenting, datatypes and operators, variables, strings, and lists. It explains how to access elements in a list, slice lists, and perform operations with lists. The document also covers sorting a list. useful for beginners who want to learn Python programming.
Download Python Programming: Datatypes, Operators, Variables, Strings, Lists and more Lecture notes Computational Biology in PDF only on Docsity!
Programming with Python Syntax for commenting Python interpreter will ignore any statement or line starting with ‘#* and treat it as a comment. In [1]: #Let’s print something print( Something") Something In the above code, we can see that the line started with '#' was ignored. Datatypes and Operators Datatypes: + int (means integer, or a whole number) + float (means floating point, or decimal number) + bool (means boolean, or a True/False) + str (means string, or ‘a piece of text’) In [@]: print(type(4)) # integer, or a whole number print(type(4.2)) # floating point, or decimal. number print(type(True)) # boolean, or a True/False print(type(‘ATGAATGC')) # means string, or ‘a piece of text’ Some mathematical operators in python Symbol Name + Addition Subtraction Multiplication Division Power Modulo - Assingment Operator ert In [0]: # Addition print(4 + 6) #Integer + Interger print(4 + 6.0) #Znteger + Float # Subtraction print (6-3) #Integer - Interger print(6-3.@) #Integer - Float # Multiplication print(2 * 5) #Integer * Interger print(2 * 5.0) #Integer * Float # Division print (24/3) # Power print(2**8) #Integer ** Interger print(2**8.0) #Integer ** Float 10 10.0 3 3.8 10 10.0 8.0 256.0 In [8]: # ‘%’ or modulo operator, also known as the remainder operator, its give the remainder of two numbers which are not a factor # of each other 8x3, out[s]: 2 Order of operation - PEMDAS 1. Parentheses () 2. Exponent **