Introduction to Python 3 Cheat Sheet
Python is a high-level programming language which was designed by Guido Van Rossum and developed by Python software foundation in 1990. It has a paradigm of Object oriented, imperative and procedural reflective. The parent company of python is a Python software foundation. It is used for web development, software development, and system scripting. now learn about the Python 3 cheat sheet
Importance of Python
- It can work with a different platform like MacOs, Windows and Linux.
- The Program in python 3 CheatSheet can be written in few lines in comparison with other programming languages.
- Python supports the procedural, object-oriented or functional way of programming.
How to install Python in your system?
- You can install python in your system free by going on the below link :
https://www.python.org/ - Once Python is installed in your system type the command python –version it will reflect the install version of the python.
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 is your name?
- If you want to comment down something in python using the below procedure:
#comment which you want to put.
Python 3 Cheat Sheet
Some of the Python 3 Cheat Sheet are given below:
Storing variable
Print(“Hello World”) and the out will be Hello World.
Hello message with a variable
a = “Hello World”
Print(a)
How to deal with a list in the python3 Cheat sheet?
car = [‘Maruti’, ‘Audi’, ‘Ford’]
Getting the first item from the list
first_car = car[0]
Adding item to the list
car = []
append(‘Maruti’)
Slicing a list
car = [‘Maruti’, ‘Audi’, ‘Ford’]
first_two = car[:2]
list.append(val) → (add item at end)
list.extend (seq) → (add a sequence of an item at the end)
list.insert (idx,val) → (insert item at index)
list.remove (val) → (remove the first item with value val)
list.pop([idx]) → value (remove and return item at index idx)
list.sort (Sort the list)
list.reverse (Reverse the list)
Tuples
Tuples are similar like the list but the only difference is that items of the list cannot be modified.
area = (1000, 2000)
Conditional operators
equals | x == 42 |
not equal | x!= 42 |
greater than | x > 42 |
greater than or equal to | x >= 42 |
less than | x < 42 |
less than or equal to | x <= 42 |
Dictionaries
Dictionaries stores the connections between the data For Eg:
car = {'color': 'green', 'seats': 5}
User Input
Forgetting the data from the user we use this syntax.
name = input("What's your name? ")
This will generate the output of — What’s your name?
4.8 (7,854 ratings)
View Course
Variable assignments
In this python 3 cheat sheet command we can define the variables by the following way:
x=2.2+9+cos(y)
a=b=c=0 (assignment to same value)
y, z, r=2, -7.6, 0 (multiple assignments)
a, b=b, a (values swap)
a,*b=seq
*a, b=seq (item and list)
x+=3 (Increment → x=x+3)
x-=2 (decrement → x=x-2)
x=None (Constant value)
del x (remove name x)
Conversions
int (“19”) → 15
int (“3f”,19) → 72 (Can specify integer number base in 2nd parameter
int (15.56) → 15 (Truncate decimal part)
float(“-12.24e9”) → -12240000000.0
round(15.56,1)→ 15.6 (rounding to 1 decimal)
bytes ([71,6,90]) → b'G\x06Z'
list(“abc”) → [‘a’,’b’,’c’]
set([“one”, “two”]) → {‘one’, ‘two’}
Spitted on white spaces → list of str, For example:
“I am back”.split() → [‘I’, ‘am’, ‘back’]
Spitted on seperator → list of str, For example:
“I, am, back”.split() → [‘I’, ‘am’, ‘back’]
Sequence container indexing
Suppose there is a list = [10, 20, 30, 40, 50] for this list indexing will be like this:
list[0] = 10
list[1] = 20
list[2] = 30
list[-1] = 50
list[-2] = 40
list[:-1] → [10,20,30,40]
list[1:-1] → [20,30,40]
list[::2] → [10,30,50]
list[::-1] → [50,40,30,20,10]
list[::-2] → [50,30,10
list[:] → [10,20,30,40,50]
list[1:3] → [20,30]
list[-3:-1] → [30,40]
list[:3] → [10,20,30]
list[3:] → [40,50]
Maths
sin(pi/4) → 707
cos(2*pi/3) → -0.4999
sqrt(81) → 9.0
log(e**2) → 2.0
ceil(12.5) → 13
floor(12.5) → 12
Display
Sep= “ “ (item seperator, default space)
end= “\n” (end of print, default new line)
file=sys.stdout (print to file, default standard output)
Generic operations on containers
len(c) → items count
min(c) → minimum
max(c) → maximum
Sum(c) → sum of the list
sorted(c) → list in sorted manner
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 Python2 str type is ASCII but in version 3 it is Unicode.
Conclusion
In the current era of Technology python, 3 Cheat Sheet is a great way of learning a programming language. Many companies are now using it like Google, Facebook, YouTube. If you are a python3 developer then you can earn up to 92000$ every year.
Recommended Articles
This has been a guide to Python 3 Cheat Sheet. Here we have discussed basic concept, and command as well as free tips and tricks of Python 3 cheat sheet. You may also look at the following article to learn more –