0% found this document useful (0 votes)
41 views2 pages

Python Quick Reference Sheet

This document is a quick reference sheet for Python, covering basics, data types, control flow, functions, object-oriented programming, and file handling. It includes examples of common methods for strings, lists, sets, and dictionaries. The information is structured for quick access to essential Python syntax and functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Python Quick Reference Sheet

This document is a quick reference sheet for Python, covering basics, data types, control flow, functions, object-oriented programming, and file handling. It includes examples of common methods for strings, lists, sets, and dictionaries. The information is structured for quick access to essential Python syntax and functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Quick Reference Sheet

1. Basics & Syntax


Python is a high-level, interpreted language used for web, data, automation, AI, and more. It
supports procedural, object-oriented, and functional programming.
Run Python: python3 [Link]
Comments: # single line, ''' multi-line '''

2. Data Types & Conversions


Type Example Convert
int x=5 int('5')
float y = 3.14 float('3.14')
str name = 'John' str(42)
bool flag = True bool(0)

3. Control Flow
if x > 0: print('Positive') else: print('Negative')
for i in range(5): print(i) while x < 5: x += 1

4. Functions
def greet(name): return f'Hello {name}' lambda x: x**2

5. OOP (Classes & Objects)


class Dog: def __init__(self, name): [Link] = name def bark(self): print('Woof')

6. File Handling & JSON


with open('[Link]', 'w') as f: [Link]('Hello') import json data = {'name':'John'} json_str =
[Link](data) [Link](json_str)
Most-Used Python Methods
Category Method Purpose / Example
Strings .lower() Convert to lowercase
Strings .split() Split into list → 'a b'.split()
Strings .replace(a,b) Replace text
Strings .count(x) Count occurrences
Lists .append(x) Add item to end
Lists .sort() Sort list
Lists .pop(i) Remove item by index
Lists .extend(lst) Add multiple items
Sets .add(x) Add element
Sets .union(s2) Combine sets
Sets .intersection(s2) Common elements
Sets .difference(s2) Difference between sets
Dictionaries .get(k) Get value by key
Dictionaries .update({...}) Update dict
Dictionaries .keys() Return keys
Dictionaries .items() Return key-value pairs

You might also like