Program 3
Program 3
Here’s a simple list of essential Python commands and keywords for beginners:
Basic Commands
1. print() – Display output.
2. input() – Take user input.
3. len() – Find the length of an object.
4. type() – Check the type of a variable.
5. str(), int(), float() – Type conversion.
6. range() – Generate a sequence of numbers.
7. sorted() – Sort items in a list.
8. max() / min() – Find the maximum or minimum.
9. sum() – Calculate the sum of items in a list.
Math Commands
10. abs() – Absolute value.
11. round() – Round a number.
12. pow() – Raise to a power.
List Methods
13. .append() – Add an item to a list.
14. .remove() – Remove an item from a list.
15. .pop() – Remove and return the last item.
16. .sort() – Sort a list.
17. .reverse() – Reverse the list order.
String Commands
18. .lower() – Convert to lowercase. [ name=("SNEHASIS"), print(name.lower()) # output: Snehasis]
19. .upper() – Convert to uppercase.
20. .strip() – Remove whitespace.
21. .split() – Split a string. [text = "apple,banana" , print(text.split(",")) # Output: ['apple', 'banana']
22. .replace() – Replace parts of a string. [text = "I like cats" print(text.replace("cats", "dogs")) # Output: I like
dogs
Error Handling
30. try / except – Handle errors.
Importing Modules
31. import – Import a module (e.g., math).
32. from – Import specific parts of a module.
Miscellaneous
33. def – Define a function.
34. return – Return a value from a function.
35. with – Context manager (e.g., for file handling).
36. break – Exit a loop early.
37. continue – Skip the current iteration.