Python Basics Recap (Automate the Boring Stuff - Unit 1)
1. print()
Displays output to the screen.
Example:
print("Hello, world!")
2. input()
Takes user input as a string.
Example:
name = input("Enter your name: ")
3. len()
Returns the number of characters/items.
Example:
len("Kaif") # 4
4. str(), int(), float()
Converts values between types.
Examples:
str(42), int('7'), float('3.14')
5. Escape Characters
\n (newline), \t (tab), \\ (backslash), \", \'
Example:
print("He said, \"Hi.\"")
6. String Concatenation & Repetition
'Hello' + 'World' -> 'HelloWorld'
'Hi' * 3 -> 'HiHiHi'
Python Basics Recap (Automate the Boring Stuff - Unit 1)
7. String Indexing & Slicing
Access parts of strings:
name[0] -> 'K'
name[1:3] -> 'ai'
8. String Methods
Useful methods:
- upper(), lower(), isalpha(), isdecimal()
- join(), split(), strip(), replace()
Example:
'-'.join(['a', 'b']) -> 'a-b'
9. Booleans & Expressions
True / False values from comparisons:
1 < 2 -> True
'hi' == 'Hi' -> False
10. Comparison Operators
==, !=, <, >, <=, >= -> used for comparisons
11. type()
Returns data type of value:
type("hello") -> <class 'str'>
12. Variables
Used to store data:
age = 18
name = "Kaif"
Python Basics Recap (Automate the Boring Stuff - Unit 1)
13. Comments
Non-executed notes:
# This is a comment
Bonus: Operators
Arithmetic: + - * / ** // %
Assignment: = += -=
Logical: and, or, not