Episode #27 | Python Values, Types and Reserved Keywords


Tuesday, 14 May 2019 Kudzai Nyandoro 6:29 Minutes

Description:

In this episode, we are going to learn how to use the Python interpreter to find out what the Python reserved keywords are.

Notes:

Values and Types
- One of the most basic things that a program works with is a value e.g. Kudzai, 4, 10, 20 etc.
- Every value has a type that it belongs to. For example 1.2 is a floating point number, the strung letters, My name is Kudzai belong to the type string.
- We can Python interpreter to find out what type a value is as shown in the example below.

>>> type('Hello World!')
# String
<class 'str'>
>>> type(1.2)
# Floating point number
<class 'float'>
>>> type(20)
#Integer, whole number
<class 'int'>
>>>
  • When a value is given a name it is called a variable.
>>> import keyword

# Test to see if a string is a keyword.

>>> keyword.iskeyword('kudzai')
False

>>> keyword.iskeyword('as')
True

>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async',
'await', 'break', 'class', 'continue', 'def', 'del', 'elif',
'else', 'except', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass',
'raise', 'return', 'try', 'while', 'with', 'yield']