Python Reserved Words – Free Python Tutorials

Reserved Words in Python

  • Reserved words are those words that have a particular meaning and functionality related to it for the compiler.
  • Python has only 33 reserved words which make it easy to remember and used when needed.
  • Some of these reserved words are:
True False None and or not is
if else elif while for break continue
return in yield try except finally raise
assert import from as class def pass
global nonlocal lambda del with

Note:

  • raise works the same as throw in exception handling.
  • lambda is used for taking an unnamed anonymous function.
  • assert is used while debugging in Python.
  • All the reserved words contain only alphabetic characters and no digits, special characters, etc.
  • The reserved words in Python have all lowercase letters except True, False and None. These three reserved words begin with an Uppercase Alphabet.

Example Program :

>>> s= True

>>> s

Output : – True


Example Program –

>>> s= true

>>>s

Output : –
NameError: name ’true’ is not defined

  • To view all the 33 keywords in Python we can use the following code.

import keyword
keyword.kwlist

In Python, the word keyword denotes a specific module in which kwlist is variable whose value is being printed through this code.


Datatypes in python :

It represents the type of data that the value is representing. It is a dynamically typed programming language which means that we don’t have to pre-define the data type of the variable while declaring it.

  1. Int:- It stores the integral values.
  2. float:- It stores the values with a floating point.
  3. complex:- It can be used for storing and manipulating numbers with an imaginary part.
  4. str:– It is used while handling strings.
  5. bool:- It is used while dealing with logical values like true and false.
  6. bytes:- A group of byte values can be termed as byte data type. 
  7. bytearray:- Its the same as a byte.
  8. range:- It represents a range of numbers.
  9. list:- It is a collection of values like an array.
  10. tuple:- Its the same as that of a list but can be mutable and non-mutable
  11. set:- It is a list of values without duplicates.
  12. frozenset:- It is a list of values without duplicates and it can’t be modified.
  13. dict:- It is the key value.
  14. None:- It means an empty or null value.

Note : In Python, everything is an object and there are many predefined functions provided by Python.


  1. int data type : The int or integer data type is used to hold integral values i.e. whole numbers without a decimal point.

Example:

>>> num= 5

>>> type(num)

<class ‘int’>

>>>print(num)

OUTPUT: 5

In the above program we see the simple use of an int type variable num to hold integral value. We print the value using print() function.
Here internally the class with class name int is available in which num is an object.

Note: long data type is not present in Python 3 as the same task can be done using int data type.


Integral values can be represented in four ways:-

  1. Decimal Form:- These are the values with base 10 and the digits used range from 0 to 9.
  2. Binary Form:-  These are the values with base 2 and the digits used are only 0 and 1.
  3. Octal Form:-   These are the values with base 8 and the digits used range from 0 to 7.
  4. Hexadecimal Form:- These are the values with base 16 and the digits used range from 0 to 9 and alphabets from A to F.

Note:- Alphabets can be both in uppercase and lowercase.

This is all about the Python data types and reserved keywords.

Leave a Comment

Your email address will not be published. Required fields are marked *