Logo

Codcups

Complete Python Reference's

Intro Of Python Programming

Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum and first released in 1991. It emphasizes code readability with its clean and easy-to-learn syntax.

🔑 Python Keywords

KeywordDescription
FalseBoolean false value
NoneRepresents null value
TrueBoolean true value
andLogical AND
asCreate an alias
assertDebugging check
asyncDeclare async function
awaitAwait result from coroutine
breakExit the loop
classDefine a class
continueSkip iteration
defDefine a function
delDelete variable/object
elifElse if condition
elseElse condition
exceptException handling
finallyAlways run after try
forFor loop
fromImport specific parts
globalDeclare global variable
ifIf condition
importImport module
inMembership test
isObject identity test
lambdaAnonymous function
nonlocalUse outer variable in nested function
notLogical NOT
orLogical OR
passDo nothing
raiseRaise exception
returnReturn from function
tryTry block
whileWhile loop
withContext manager
yieldReturn generator

🧪 Python Data Types

Data TypeDescriptionExample
intInteger numbersx = 10
floatDecimal numbersx = 3.14
complexComplex numbersx = 2 + 3j
boolBoolean valuesTrue or False
strText / Strings"Hello"
listOrdered, mutable list[1, 2, 3]
tupleOrdered, immutable list(1, 2, 3)
setUnordered, unique elements{1, 2, 3}
dictKey-value pairs{'a': 1, 'b': 2}
bytesImmutable byte sequencesb'hello'
bytearrayMutable byte sequencesbytearray(5)
NoneTypeRepresents a null valueNone

⚙️ Python Operators

Operator TypeOperatorsExample
Arithmetic+ - * / % // **a + b
Assignment= += -= *= /= %= //= **=x += 1
Comparison== != > < >= <=a == b
Logicaland or nota and b
Membershipin not in"a" in "abc"
Identityis is nota is b
Bitwise& | ^ ~ << >>a & b

🧰 Python Built-in Functions

FunctionDescription
print()Prints output
input()Takes user input
len()Returns length
type()Returns data type
range()Returns a range of values
int()Converts to integer
float()Converts to float
str()Converts to string
list()Converts to list
dict()Creates dictionary
set()Creates set
tuple()Creates tuple
sum()Sums iterable
min()Minimum value
max()Maximum value
sorted()Returns sorted list
abs()Absolute value
round()Rounds number
enumerate()Returns index and item
zip()Combines iterables into tuples

🧱 Python Common Tags & Constructs

ConstructPurposeExample
if-elseConditional logicif x > 5: print("Yes")
for loopLoop over sequencefor i in list:
while loopLoop while condition is truewhile x < 5:
defFunction definitiondef greet():
classDefine classclass Person:
try-exceptError handlingtry: x = 1/0 except:
withContext managementwith open("file.txt") as f:
importImport moduleimport math
lambdaAnonymous functionlambda x: x + 1
returnReturn value from functionreturn x
yieldGenerate valuesyield x

Click to go back on notes page.