Crash Course Python by Anuj

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Python

CRASH Course

Variables & data types


- Variables name can only contain number, _ , chars
- Name can not start with a number
- No space in variable names

Strings
- Changing case in string:
print(name.title())
print(name.upper())
print(name.lower())
2

Concat variables using f, These strings are called f-strings. The f is for format, because Python formats the string by
replacing the name of any variable in braces with its value.

Fname="Anuj"
Lname="Tomar"
fullname=f"{Fname} {Lname}"
print(f"FullName, {fullname.title()}!")

Adding whitespace to strings with tabs or newlines


print("Cities: \n\tGwalior\n\tGreaterNoida\n\tDelhi\n\tPune")

print("Stripping Whitespaces from strings")


rname="Anuj "
lname=" Anuj"
bname=" Anuj "
print(f"{rname}!")
print(f"{rname.rstrip()}!")

print(f"{lname}!")
print(f"{lname.lstrip()}!")

print(f"{bname}!")
print(f"{bname.strip()}!")

Strip whitespaces from either left, right or both sides,

Avoiding Syntax Errors with Strings


- Special chars in double quotes will be interpreted as it is but in single quotes might give error
message = "One of Python's strengths is its diverse community." - OK
message = 'One of Python's strengths is its diverse community.' - Syntax
Error

Functions as BlackBoxes
Abstraction - Just use a function without knowing how it is implemented.

You might also like