Python Cheat Sheet

From basics to advanced — Python at your fingertips.

Python Cheat Sheet by InterviewZilla

Who We Are

We strive to provide the best resources and guidance to help you succeed in your career journey. We’d love to hear from you if you have any questions, suggestions, or feedback. Our team is here to assist you with any inquiries about our interview preparation services, job search strategies, or any other aspect of our platform. Feel free to contact us using the contact form below, and we’ll get back to you as soon as possible. Your insights are essential to us as we continuously improve our offerings and ensure your success in the competitive job market.
Together, we can shape a future filled with growth and success.

🔹 Basics

1. Print & Comments

python
# Printing a simple message
print("Welcome to InterviewZilla!")


""" Multi-line comment or docstring
Used for documentation """

2. Variables

python
# Assigning values to variables
x = 10
name = "InterviewZilla"
active = True


print(name, "rocks!")

3. Multiple Assignment

python
# Assign multiple variables in one line
a, b, c = "Python", "Data", "InterviewZilla"
print(a, b, c)

4. Data Types

python
# Integer, Float, String, Boolean
num = 100
price = 99.9
brand = "InterviewZilla"
active = True


print(type(price))

🔹 Strings & Collections

5. String Methods

python
s = "interviewzilla"
print(s.upper()) # INTERVIEWZILLA
print(s.title()) # Interviewzilla

6. String Formatting

python
name = "Om"
print(f"Hello {name}, Welcome to InterviewZilla!")

7. Lists

python
topics = ["Python", "Spark"]
topics.append("InterviewZilla")
print(topics)

🔹 Virtual Environment & Pip

33. Virtual Env

bash
python -m venv env
source env/bin/activate

34. Install Package

bash
pip install requests

🔹 Popular Libraries

35. NumPy

python
import numpy as np
arr = np.array([1,2,3])
print(arr.mean())

36. Pandas

python
import pandas as pd
df = pd.DataFrame({"Brand":["InterviewZilla"]})
print(df)

37. Requests

python
import requests
r = requests.get("https://api.github.com")
print(r.status_code) # 200 if successful

38. JSON

python
import json
data = {"brand": "InterviewZilla"}
print(json.dumps(data))

🔹 Extras

39. f-strings

python
brand = "InterviewZilla"
print(f"Best brand: {brand}")

40. Slicing

python
s = "InterviewZilla"
print(s[:9]) # Interview

41. Type

python
x = 10
print(type(x)) # 

42. Round

python
pi = 3.14159
print(round(pi, 2)) # 3.14

43. Sorted

python
nums = [3,1,2]
print(sorted(nums))

44. Map

python
nums = [1,2,3]
print(list(map(lambda x: x*2, nums)))

45. Filter

python
nums = [1,2,3,4]
print(list(filter(lambda x: x%2==0, nums)))

46. Range

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

47. Help

python
help(len) # Shows documentation for len()

48. Dir

python
print(dir(str)) # Lists all attributes of string class

49. Import Alias

python
import numpy as np
print(np.pi)

50. With Context

python
with open("iz.txt") as f:
print(f.read())