Skip to main content

Python keyword and identifiers

Python Keywords

Keywords are the reserved words in Python.
We cannot use a keyword as variable namefunction name or any other identifier. They are used to define the syntax and structure of the Python language.
In Python, keywords are case sensitive.
There are 33 keywords in Python 3.3. This number can vary slightly in course of time.
All the keywords except TrueFalse and None are in lowercase and they must be written as it is. The list of all the keywords are given below.

Keywords in python programming language

  1. True
  2. False
  3. None
  4. and
  5. as
  6. assert
  7. break
  8. class
  9. continue
  10. def
  11. del
  12. elif
  13. else
  14. except
  15. finally
  16. for
  17. from
  18. global
  19. if
  20. import
  21. in
  22. is
  23. lambda
  24. nonlocal
  25. not
  26. or
  27. pass
  28. raise
  29. return
  30. try
  31. while
  32. with
  33. yield

Python Identifiers

Identifier is the name given to entities like class, functions, variables etc. in Python. It helps differentiating one entity from another.

Rules for writing identifiers

  1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore (_). Names like myClassvar_1 and print_this_to_screen, all are valid example.
  2. An identifier cannot start with a digit. 1variable is invalid, but variable1 is perfectly fine.
  3. Keywords cannot be used as identifiers.
  4. We cannot use special symbols like !, @, #, $, % etc. in our identifier.
  5. Identifier can be of any length.

Things to care about

Python is a case-sensitive language. This means, Variable and variable are not the same. Always name identifiers that make sense.
While, c = 10 is valid. Writing count = 10 would make more sense and it would be easier to figure out what it does even when you look at your code after a long gap.
Multiple words can be separated using an underscore, this_is_a_long_variable.
We can also use camel-case style of writing, i.e., capitalize every first letter of the word except the initial word without any spaces. For example: camelCaseExample




Comments

Popular posts from this blog

Python Introduction

What is Python? https://drive.google.com/file/d/12anPuRDTNSLdI6JhzNtRRbKeHnOfnJy3/view?usp=drivesdk Python is a popular programming language. It was created in 1991 by Guido van Rossum. It is used for: web development (server-side), software development, mathematics, system scripting. Python is a widely used general-purpose, high level programming language. It was initially designed by  Guido van Rossum  in 1991  and developed by Python Software Foundation.  It was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code. Python is a programming language that lets you work quickly and integrate systems more efficiently. The Python  IDLE  (Integrated Development Environment)  executes instructions one line at a time.  This also lets us use it as a calculator. There are two major Python versions-  Python 2 and Python 3 . Both are quite d...

Python Data Types

Data Type in Python:- Python data types are different in some aspects from other programming languages.  It is simple to understand and easy to use.  Because Python is interpreted programming language and Python interpreter can determine which type of data are storing, so no need to define the data type of memory location. Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes. The data type determines: - ·          The possible values for that type. ·          The operations that can be done with that values. ·          Conveys the meaning of data. ·          The way values of that type can be stored. *There are various data types in Python. Some of the important type...