0% found this document useful (0 votes)
15 views11 pages

Python Basics Cheat Sheet

The document provides an overview of Python, highlighting its features such as being a high-level, interpreted, and dynamically typed language created by Guido van Rossum in 1991. It covers basic data structures like lists, tuples, dictionaries, and sets, as well as fundamental programming concepts including variables, control flow, functions, file handling, and error management. Additionally, it mentions popular libraries like Numpy, Pandas, Matplotlib, and Seaborn used for various applications in data science and visualization.

Uploaded by

CatraX
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
15 views11 pages

Python Basics Cheat Sheet

The document provides an overview of Python, highlighting its features such as being a high-level, interpreted, and dynamically typed language created by Guido van Rossum in 1991. It covers basic data structures like lists, tuples, dictionaries, and sets, as well as fundamental programming concepts including variables, control flow, functions, file handling, and error management. Additionally, it mentions popular libraries like Numpy, Pandas, Matplotlib, and Seaborn used for various applications in data science and visualization.

Uploaded by

CatraX
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 11

Tajamul Khan

@Tajamulkhann
Python: A high-level, general-purpose
language.
Language Type: Interpreted and
dynamically typed.
Founder: Created by Guido van
Rossum, 1991.
Interpreter: Executes code line by line.
Uses: Used in Data Science, Web
Development, AI, etc.
Syntax: Simple and beginner-friendly.
Cross-Platform: Works on Windows,
macOS, Linux.
Open-Source: Free to use, modify, and
redistribute.
Extensive Libraries: Includes tools for
scientific computing, Web
development, Machine Learning,
Generative AI etc.

@Tajamulkhann
List: An ordered, mutable collection of
elements.
lst = [1, 2, 3, 4]

Tuple: An ordered, immutable collection


of elements.
tpl = (1, 2, 3, 4)

Dictionary: A collection of key-value


pairs.
dct = {"a": 1, "b": 2}

Sets: An unordered collection of unique


elements.
st = {1, 2, 3}

@Tajamulkhann
Variables: store data values.
x = 10

Indentation: defines blocks of code in


Python.
if True:
print("Indentation matters!")

Comments: explain code and are


ignored by the interpreter

# This is a single-line comment

""" This is a multi-line comment """

@Tajamulkhann
Numeric: Represent numbers
(integer, float, complex).
a = 10 # int
b = 3.14 # float
c = 2 + 3j # complex

String: A sequence of characters.


s = "Hello"

Boolean: Represents True or False.


is_active = True

@Tajamulkhann
If-Else Statements: Conditional
statements to execute specific code
blocks.
if x > 0:
print("Positive")
else:
print("Negative")

For Loops: Iterate over a sequence.


for i in range(5):
print(i)

While Loops: Repeat a block of code


while a condition is true.
while x > 0:
print(x)
x -= 1

@Tajamulkhann
Self-defined Functions: Functions that
are defined by the user to perform
specific tasks.
def function_name(parameters):
return value

Lambda Functions: Anonymous one-line


functions defined using the lambda
keyword.
square = lambda x: x**2

Inbuilt Functions: Functions that are


built into Python and available for
immediate use.
print("Hello World!")
print(type(10))

@Tajamulkhann
Reading Files: Open and read contents
from a file.
with open("file.txt", "r") as f:
content = f.read()
print(content)

Writing Files: Open and read contents


from a file.
with open("file.txt", "r") as f:
content = f.read()
print(content)

@Tajamulkhann
Try-Except: Handle errors gracefully.
try:
x=1/0
except ZeroDivisionError:
print("Cannot divide by zero!")

Finally Block: Ensure cleanup after a try


block.
try:
f = open("file.txt", "r")
finally:
f.close()

@Tajamulkhann
Numpy: for numeric computations.
import numpy as np
arr = np.array([1, 2, 3])

Pandas: for data manipulation.


import pandas as pd
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})

Matplotlib: Data visualization library


import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()

Seaborn: Advanced visualization library.


import seaborn as sns
sns.barplot(x=["A", "B"], y=[10, 20])

@Tajamulkhann
Follow for more!

You might also like