The document provides an overview of variables, identifiers, and keywords in Python, explaining how variables are assigned values and can change types during execution. It details the rules for naming identifiers, including case sensitivity and restrictions on characters, as well as the significance of keywords that have predefined meanings in Python. Examples are provided to illustrate these concepts and their proper usage.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views
Variables, Identifiers and Keywords in Python
The document provides an overview of variables, identifiers, and keywords in Python, explaining how variables are assigned values and can change types during execution. It details the rules for naming identifiers, including case sensitivity and restrictions on characters, as well as the significance of keywords that have predefined meanings in Python. Examples are provided to illustrate these concepts and their proper usage.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7
K.C.S.
KASI NADAR COLLEGE OF ARTS & SCIENCE
(Belongs to S.V.H.N.A.Dharma Fund)
VARIABLES, IDENTIFIERS AND
KEYWORDS IN PYTHON By, Mrs.B.VIJAYALAKSHMI, Assistant Professor, Department Of Computer Science. VARIABLES • A variable is a name that is associated with a value. • The assignment operator, = , is used to assign values to variables. • An immutable value is a value that cannot be changed. Eg: >>>num=10 >>> k=num >>> print(k) O/P : 10 • In Python the same variable can be associated with values of different type during program execution. Eg : var = 12 integer var = 12.45 float var = 'Hello' string VARIABLE ASSIGNMENT AND KEYBOARD INPUT • The value can come from the user by use of the input function. Eg : >>> name=input('what is your name : ') O/P : what is your name : ABC • All input is returned by the input function as a string type. • For the input of numeric values, Python provides built-in type conversion functions int() and float(). Eg : >>> age=int(input('Enter your age : ')) O/P : Enter your age : 18 IDENTIFIER • An identifier is a sequence of one or more characters used to name a given program element. • Python is case sensitive. Eg : username is not same as userNAME. • Identifiers may contain letters and digits, but cannot begin with a digit. • The underscore character, _, is also allowed but it should not be used as the first character. • Spaces are not allowed as part of an identifier. NAMING AN IDENTIFIER Valid identifiers Invalid identifiers Reason invalid
totalSales ‘totalsales’ Quotes not allowed
totalsales Total sales Spaces not allowed
salesFor2020 2020sales Cannot begin with a digit
Sales_for_2020 _sales2020 Should not begin with an
underscore
• To check whether a given identifier is a keyword in python.
>>> 'exit' in dir(__builtins__) O/P : True >>> 'exit_program' in dir(__builtins__) O/P : False KEYWORDS IN PYTHON • A keyword is an identifier that has predefined meaning in a programming language. • Cannot be used as a “regular” identifier. Eg: >>> and=10 O/P : SyntaxError: invalid syntax THANK YOU!!!