Advertisement
Aminechbani2

Python

Jul 5th, 2024
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | Source Code | 0 0
  1. #Variables:
  2.     examplevar = "string"
  3.     examplevar = 25 #integer
  4.     examplevar = 2.5 #float
  5.     examplevar = True #boolean
  6. #Strings:
  7.     vari = "Hello " + "there" #concatenated
  8.     vari = f"{25} tomatoes" #formatted
  9. #Input & Output:
  10.     name = input("Enter your name:") #input
  11.     print(name) #output
  12. #Type Conversion:
  13.     str()
  14.     int()
  15.     float()
  16.         num = 20/5 #dividing an int always results in a float (implicit conversion)
  17.         num = 20+2.5 #operations between an int and a float always result in a float
  18.     bool()
  19. #Comparison:
  20.     > #greater
  21.     <= #less or equal
  22.     == #equal
  23.     != #inequal
  24. #Logical operations:
  25.     op = True or False #=True
  26.     op = True and False #=False
  27. #Loops:
  28.     for num in range(10): #for loop
  29.         print(num)
  30.     while num < 5:  #while loop
  31.         num = num+1
  32. #Conditional statements:
  33.     if num >= 5
  34.         print("one")
  35.     elif num >=3:
  36.         print("two")
  37.     else:
  38.         print("three")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement