Building Blocks of Python: Keywords

 Building blocks of Python

1. Python Keyword

2. Identifiers

3. Comments in Python

4. Python Indentation

5. Python Statement


One of the most basic command used in Python is print command:


1. Python Keywords

Python has a set of keywords that are reserved words that cannot be used as variable names, function names, or any other identifiers.

  • Must be spelled exactly as they are written
  • There are 35 keywords in Python 3.8.8
  • There were 33 keywords in Python 3.6



The list of keywords is as follows
1. False: Boolean value, result of comparison operations

2. None: Represents a null value

3. True; Boolean value, result of the comparison operation

4. and: a logical operator; boolean operator for and operation

5. as: to create alias

6. assert: for debugging

7. async: always used in couroutine function body. It’s used with asyncio module and await keywords.

[ refer to: https://www.askpython.com/python/python-keywords

and

https://www.infoworld.com/article/3454442/get-started-with-async-in-python.html ]

8. await: for asynchronous processing.

[ refer to : https://stackabuse.com/python-async-await-tutorial/   ]

9. break: to break out of a loop; used with nested "for" and "while" loops. It stops the current loop execution and passes the control to the start of the loop

10. class: to define a class

11. continue: to continue the next iteration of a loop

12. def: to define a function

13. del: to delete an object

14. elif: used in conditional statements, same as else if

15. else: used in conditional statement

16. except: used with exceptions, what to do when an exception occurs

17. finally: used with exceptions, a block of code that will be executed no mater if there is an exception         or not

18. for: to create a for loop; used to iterate over the elements of a sequence or iterable object

19. from: to import specific parts of a module

20. global: to declare a global variable

21. if: to make a conditional statement

22. import: to import a module

23. in: to check if a value is present in a list, tuple, etc.

24. is: to test if two variables are equal

25. lambda: to create an anonymous function

26. nonlocal:  to declare a non-local variable

27. not: a logical operator; used for Boolean not operator

28. or: a logical operator; Boolean operator [ x = True or False ]

29. pass: a null statement, a statement that will do nothing

30. raise: to raise an exception

31. return: to exit a function and return a value

32. try: to make a try....except statement; used to write exception handling code

33. while: to create a while loop; to run a block of statements till the expression is true

34. with: used to simplify exception handling; used to wrap the execution of a block with methods defined by a context manager. The object must implement __enter__() and __exit__() functions

35. yield: to end the function, returns a generator; is a replacement of return keyword. This is used to return values one by one from the function

The new keywords are "async" and "'await"


reference text for keywords

Comments