Python : Basics Cheat Sheet

Python : Basics Cheat Sheet

·

2 min read

Cheat sheet for Python basics:

Data Types:

- int: integer
- float: floating-point number
- str: string
- bool: boolean (True or False)
- list: ordered collection of values
- tuple: ordered, immutable collection of values
- set: unordered collection of unique values
- dict: unordered collection of key-value pairs

Variables:

variable_name = value

Printing:

print("Hello, world!")

User Input:

input("Enter your name: ")

Arithmetic Operators:

+  -  *  /  //  %  **

Comparison Operators:

==  !=  <  >  <=  >=

Logical Operators:

and  or  not

Conditional Statements:

if condition:
    # code to run if condition is true
elif condition2:
    # code to run if condition2 is true
else:
    # code to run if all conditions are false

Loops:

while condition:
    # code to run while condition is true

for variable in iterable:
    # code to run for each value in iterable

Functions:

def function_name(parameter1, parameter2):
    # code to run
    return result

Built-in Functions:

- print()
- input()
- len()
- range()
- type()
- int()
- float()
- str()
- bool()
- list()
- tuple()
- set()
- dict()

Remember, this is just a basic cheat sheet. There is much more to learn about Python, but mastering these fundamentals will give you a strong foundation to build on.