Python Character Set
Tokens
Keyword
Identifiers
(Names)
Literals
Operators
Punctuators
Keywords
A
keyword is a word having special meaning reserved by the programming language.
More
on keywords….
¨ In Python,
keywords are case sensitive.
¨All
the keywords except True, False and None are in lowercase and they must be
written as it is. The list of all the keywords are given below.
Python
Identifiers
¨Identifier
is the name given to entities like class, functions, variables etc. in Python.
It
helps differentiating one entity from another.
Rules
for writing identifiers
¨Identifiers
can
be a combination of letters in lowercase (a to z) or uppercase (A to Z) or
digits (0 to 9) or an underscore (_). Names like myClass, var_1 and print_this_to_screen,
all
are valid example.
¨An
identifier cannot start with a digit. 1variable is invalid,
but variable1 is perfectly
fine.
¨Keywords
cannot be used as identifiers.
¨We
cannot use special symbols like !, @, #, $, % etc. in our identifier.
¨Identifier
can be of any length.
Literals
¨String
Literals
¡Single
Line String
¡Multi
Line String
¡Raw
String
¡Unicode
String
¨Numeric
Literals
¡Integer
¡Float
¡Complex
¨Boolean
Literals
¨Special
Literals
¨Literal
Collection
¡List
¡Tuple
¡Dictionary
¡Set
Strings
Numeric
Literals
¨Integer
¡Decimal
¡Binary
Literal
¡Octal
¡Hexadecimal
¨Float
¨Complex
Boolean
Literals
¨There
are two kinds of Boolean
literal: True and False.
Example:
¨x =
(1 == True)
¨y =
(1 == False)
¨a =
True + 4
¨b =
False + 10
¨print("x
is", x)
¨print("y
is", y)
¨print("a:",
a)
¨print("b:",
b)
Special
Literal
Python contains one special literal
i.e. None
Example:
drink = "Available"
food = None
def menu(x):
if x == drink:
print(drink)
else:
print(food)
menu(drink)
menu(food)
Operators
¨Unary
Operator (+, -, ~, not)
¨Binary
Operator
¡Arithmetic
Operator (+, -, *, /, %, **, //)
¡Relational
Operator (<, >, <=, >=, ==, !=)
¡Logical
Operator (and, or, not)
¡Bitwise
Operator (&, ^, |, <<, >>)
¡Assignment
Operator (=, +=, -=, *=, /=, %=,**=, //=)
¡Identity
Operator (is, not is)
¡Membership
Operator (in, not in)
good job... worthy content... it's really very beneficial for other students ... keep it up...
ReplyDelete