jagomart
digital resources
picture1_Python Pdf 184205 | Python Cheat Sheet


 135x       Filetype PDF       File size 0.21 MB       Source: www.101computing.net


File: Python Pdf 184205 | Python Cheat Sheet
python language syntax cheat sheet rule 1 python is white space dependent code blocks are indented using spaces rule 2 python language is case sensitive it matters for variables functions ...

icon picture PDF Filetype PDF | Posted on 01 Feb 2023 | 2 years ago
Partial capture of text on file.
             Python Language & Syntax Cheat Sheet 
             Rule #1:  Python is white-space dependent; code blocks are indented using spaces. 
             Rule #2:  Python language is case sensitive. It matters for variables, functions and any keyword in general. 
             Variable Assignment 
             Variable Assignment                                                 IF Statements 
             myInteger = 1                                                       Warning: Use the 4 spaces rule!!! (Indentation) 
             myString = “Hello World”                                             
             myList = [ “John”, “James”, “Laura” ]                               if i == 7: 
             playerName = input ( “What’s your name?” )                              print “seven” 
                                                                                 else: 
             Basic Arithmetics                                                       print “Not seven!” 
             i = a + b                                                            
             i = a - b                                                           if i == 7: 
             i = a / b                                                               print “seven” 
             i = a * b                                                           elif i == 8: 
             i = a % b (Modulus/Remainder)                                           print “eight” 
                                                                                 elif i == 9: 
             Adding Comments / Annotations                                           print “nine” 
             # Single Line Comment                                               else: 
                                                                                     print “Not seven, eight or nine” 
             """                                                                  
             Multi-line comment                                                  Loops 
             """                                                                 Warning: Use the 4 spaces rule!!! (Indentation) 
                                                                                  
             Conversions                                                         for i in range(1,10):   #using a range 
             #To convert from a numeric type to a string:                            print i 
             str(100)                                                             
                                                                                 for i in [1, 3, 5, 7]:  #using a list 
             #To convert from a string to an integer:                                print i 
             int("100")                                                           
                                                                                 i=0 
             #To convert from a string to a float:                               while i<=100: 
             float("100.5")                                                          print i 
                                                                                  
             #e.g                                                                #When using a loop, if you want to exit the loop you can 
             myAge= int ( input( “What’s Your Age” ) )                           #use the following instruction: 
                                                                                 break 
             String Manipulation                                                  
             myString=”Hello “ + “world”                                         Comparison Operators & Conditions 
                                                                                 #These operators can be used in If Statements or with 
             #The following code would return a list as follows:                 While loops. They return True or False! 
             # [“John”,”James”,”Laura”]                                           
             myString=”John,James,Laura”                                                     a == b               Is a equal to b? 
             myString.split(“,”)                                                             a != b               Is a different from b? 
                                                                                              a < b               Is a lower than b? 
             #The following code would remove spaces at the                                   a > b               Is a greater than b? 
             #beginning and end of a string                                                  a <= b               Is a lower or equal to b? 
             myString=”   Hello    “                                                         a >= b               Is a greater or equal to b? 
             print(  myString.strip() )  # this would display “Hello”                      a is None              Is a null/none? 
                                                                                         a is not None            Is a not null/none? 
             Functions                                                           a in [“John”,”James”,”Luke”]     Is a one of the value in 
             Warning: Use the 4 spaces rule!!! (Indentation)                                                      the given list? 
                                                                                 myString.startswith("Hello")   Does myString start with 
             def  myFunction ( arg1, arg2,… ) :                                                                   the string “Hello”? 
                 #Code goes here                                                        “@” in myEmail            Does the string myEmail 
                return myValue                                                                                    contains the string “@”? 
                                                                                  
             #e.g.                                                               Importing Modules 
             def mySumFunction ( x, y, z=0 ) :                                   # Imports should be made at the top of your code: #e.g. 
                 sum = x + y + z                                                 import random 
                 return sum 
              
             print ( mySumFunction ( 1,3,5 ) )  # this would display 9 
                                                   © 101 Computing – www.101Computing.net 
              
The words contained in this file might help you see if this file matches what you are looking for:

...Python language syntax cheat sheet rule is white space dependent code blocks are indented using spaces case sensitive it matters for variables functions and any keyword in general variable assignment if statements myinteger warning use the indentation mystring hello world mylist i playername input what s your name print seven else basic arithmetics not a b elif modulus remainder eight adding comments annotations nine single line comment or multi loops conversions range to convert from numeric type string str list an integer int float while greater than beginning end of equal strip this would display none null one value given startswith does start with def myfunction arg goes here myemail return myvalue contains e g importing modules mysumfunction x y z imports should be made at top sum import random computing www net...

no reviews yet
Please Login to review.