How to Install Python in your System?
- You can install python in your system free by going to the below link:
https://www.python.org/ - Once Python is installed in your system, type the command python –version; it will reflect the python’s install version.
Some Basics of Python 3 Cheat Sheet Programming
- Your first python program. Type the below command print (“what is your name?”) and press the enter it will generate the output what your name is?
- If you want to comment down something in python using the below procedure:
#comment which you want to put.
Python 3 Cheat Sheet
Below are topics, we are using while creating a cheat sheet in python. The below example shows the python 3 cheat sheet is as follows.
Variables
Below is the example of a variable which was we are using in python 3 are as follows:
P = 5 – here we are using integer value as 5 and assigning 1 value to p variables.
Q = 5.1 – We have used the floating-point number as 5.1 and assigned this value to Q.
R = 1 + 2j – This variable is nothing but the complex number.
d = “a” – string variables
e = True # Boolean variables (True or False)
Code:
P = 5
Q = 10
R = P + Q
print (R)
Output:
String
Below example shows python 3 cheat sheet string are as follows.
a = “cheatsheet”
len (p)
p [0]
p [-1]
# Formatted strings
Stud_name = f”{first}”
# String methods
p.upper ()
p.lower ()
p.title ()
p.strip ()
p.find (“p”)
p.replace (“q”, “r”)
Code:
py = “python”
print (len (py))
Output:
Type conversion
Below example shows python 3 cheat sheet type conversion are as follows.
int(x)
float(x)
bool(x)
string(x)
Code:
p = 5
print (“p type is:”, type(p))
q = 5.7
print (“q type is:”, type(q))
Output:
Falsy Value
The below example shows python 3 cheat sheet falsy values are as follows.
0
“”
[]
Code:
p = 0
if p:
print (p)
Output:
Conditional Statements
The below example shows python 3 cheat sheet conditional statements are as follows.
if x == 10:
print(“a”)
elif y == 20:
print(“b”)
else:
print(“c”)
Code:
p = 10
q = 20
if q > p:
print (“q is greater”)
Output:
Loops
The below example shows python 3 cheat sheet loops are as follows.
for p in range(10, 15):
print (p)
while p < 15:
print (p)
Code:
for p in range(10, 15):
print (p)
Output:
Functions
The below example shows the functions are as follows.
def multiply(*numbers):
for number in numbers:
print number
Code:
def py ():
print (“py function”)
py ()
Output:
List
The below example shows the list are as follows.
py = [“p”, “q”, “r”]
py [0]
py [-1]
Code:
py = [74, 55, 37, 19, 39, 41]
print (py)
Output:
Tuples
The below example shows tuples are as follows.
p = 10
q = 11
p, q = q, p
Code:
py = (‘pink’, ‘red’, ‘black’, ‘white’, ‘green’)
print (py)
Output:
Array
The below example shows array are as follows.
from array import array
num = arr (“p”, [11, 12, 13])
Code:
py_car = [“swift”, “polo”, “BMW”]
print (py_car)
Output:
Sets
Below example shows sets are as follows.
py1 = {11, 21, 31, 41}
py2 = {11, 15}
Code:
py = {11, 12, 13}
print (py)
Output:
Dictionaries
Below example shows dictionaries are as follows.
py1 = {a: a * 5 for range(5)}
Code:
py = {11: ‘red’, 12: ‘black’}
print (py)
Output:
Generator Expressions
The below example shows generator expressions are as follows.
py = (a * 5 for py range(10))
len (py)
for a in py:
Code:
def generator():
py = 15
print (‘Result ‘,py)
yield py
py1 = generator()
next (py1)
Output:
Unpacking Operator
Below example shows unpacking operator are as follows.
p1 = [11, 12, 13]
p2 = [14, 15, 16]
p12 = [*p1, “a”, *p2]
Code:
py = [16,17,18,19,10]
print (py)
Output:
How Python 3 Cheat Sheet is Different from Version 2?
Let us know how it differs from version 2.
- Division operator: For a case 7/5 or -7/5, then the output in Python 2 will be 1 and -2, respectively, but in python3 the output will be 1.4 and -1.4.
- Unicode: In Python 2 str type is ASCII, but in version 3, it is Unicode.