Language Fundamentals
1)Tokens :
i) Identifiers ii) literals iii) keywords iv) Operators
2)Data Types
3)Type Casting : i)Implicit and ii)Explicit
4)Python Statements
Identifier
Variable means its value can vary. You can store any piece of information in a variable. Variables are
nothing but just parts of your computer’s memory where information is stored. To be identified easily,
each variable is given an appropriate name.
Identifiers are names given to identify something. This something can be a variable, function, class,
module or other object. For naming any identifier, there are some basic rules like:
• The first character of an identifier must be an underscore ('_') or a letter (upper or lowercase).
• The rest of the identifier name can be underscores ('_'), letters (upper or lowercase), or digits (0-9).
• Identifier names are case-sensitive. For example, myvar and myVar are not the same.
• Punctuation characters such as @, $, and % are not allowed within identifiers.
Examples of valid identifier names are sum, __my_var, num1, r, var_20, First, etc.
Examples of invalid identifier names are 1num, my-var, %check, Basic Sal, H#R&A, etc
• Python is case sensitive programming language.
d is not equal to D
t is not equal to T
rahul is not equal to Rahul
rahul is not eqaul to RAHUL
Note:
If the identifier starts and ends with two underscore symbols then
the identifier is language defined special name, which is also
known as magic methods. Eg: __init__
Which of the following are valid
Python identifiers
• 123total
• total123
• java2share
• 4ca$h
• _abc_abc_
• def
• if
• int
•Camel Case: Second and subsequent words are capitalized, to make word
boundaries easier to see. (Presumably, it struck someone at some point that the
capital letters strewn throughout the variable name vaguely resemble camel
humps.)
•Example: numberOfCollegeGraduates
•Pascal Case: Identical to Camel Case, except the first word is also capitalized.
•Example: NumberOfCollegeGraduates
•Snake Case: Words are separated by underscores.
•Example: number_of_college_graduates
Literals
1) Literal is a constant assigned to the variable
i) Numeric Literals:
a) int literals Eg: b=10
b) float literals Eg: b=10.5
ii)Non Numeric Literals:
a) bool Eg: b=True
b) str Eg: s1=“CVR”
Keywords or Reserved Words
In Python some words are reserved to represent some meaning or functionality. Such
type of words are called Reserved words.
Python language uses the following keywords which are not available to users to use
them as an identifiers.
['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']
Operators
An operator is a symbol that performs an operation.
• Arithmetic Operators
• Assignment Operators
• Relational Operators / Comparison Operators
• Logical Operators
• Bitwise Operators
• Ternary Operators
• Membership Operators
• Identity Operators