Page 299 - Artificial Intellegence_v2.0_Class_9
P. 299
Following is the list of keywords displayed by running the above commands:
['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']
Identifiers (Names)
Identifiers are the user-defined names of variables, list, dictionary, tuples, classes etc. They identify an element
in Python.
Naming the identifiers follows rules as given below:
• An identifier can have letters in uppercase or lowercase, numbers or underscore(_).
• It cannot begin with a number.
• No special characters like $, period(.), space, etc. are allowed.
• It should not be a Python keyword.
• Uppercase and lowercase letters are different.
Example of invalid identifiers are:
First name : Spaces not allowed.
Last&Name : Cannot have special character.
9thclass : Cannot begin with number
else : Keyword not allowed.
Example of valid identifiers are:
Myclass, class9, Address, address, first_name, city, student_id, data123
Variables
Variable is a name given to a memory location to hold a specific value. It is just like a container that can hold any
type of data that can be changed later in the program.
Variable has:
• A name that follows the rules of identifier naming conventions and is case sensitive.
• A value that can be integer, float, string, boolean, etc.
Unlike other programming languages, variables in Python are not created before. They are created automatically
when a value is assigned to it using an = operator. A variable assigned with a value of one type can be re-
assigned a new value of a different type as shown below:
>>>a = 20
>>>a
20
>>>a = "hello"
>>>a
'hello'
There are different ways of assigning values to different variables in Python:
• Method1: Assigning different values to different variable on different lines.
>>>a = 5
Introduction to Python 297

