Python Basic (3)
Python Basic (3)
In the above screen, the symbol >>> is the Python prompt, which indicates that the
interpreter is ready to take instructions.
7: Execution Modes
There are two ways to use the Python interpreter:
a) Interactive mode - Interactive mode allows execution of individual statement
instantaneously.
b) Script mode- Script mode allows us to write more than one instruction in a file
called Python source code file that can be executed.
8: Character set
A character set is a set of valid characters acceptable by a programming language
in scripting. the Python character set is a valid set of characters recognized by the
Python language. Python supports all ASCII / Unicode characters that include:
Alphabets: All capital (A-Z) and small (a-z) alphabets.
Digits: All digits 0-9.
Special Symbols: Python supports all kind of special symbols like, ” ‘ l ; : ! ~
@#$%^`&*()_+–={}[]\.
White Spaces: White spaces like tab space, blank space, newline, and
carriage return.
9: Tokens
A token is the smallest individual unit in a python program. All statements and
instructions in a program are built with tokens. The various tokens in python are :
PYTHON KEYWORDS - Keywords are reserved words. Each keyword
has a specific meaning to the Python interpreter, and we can use a keyword
in our program only for the purpose for which it has been defined. As
Python is case sensitive. Example : int , float etc
2: Relational Operators
Relational operator compares the values of the operands on its either side and
determines the relationship among them. There are six types of relational operators
Ex:
Operator Description Operator Description
== Check two values are equal != Check two values are not
equal
> Check left side value greater < Check left side value smaller
than right side value than right side value
>= Check left side value greater <= Check left side value less than
or equal to the right side or equal to the right side
value value
3: Logical Operators
There are three logical operators supported by Python. These operators (and, or,
not) are to be written in lower case only. The logical operator evaluates to either
True or False based on the logical operands on either side.
Operator Description
and If both the operands are True, then >>> num1 = 10
condition becomes True >>> num2 = -20
>>> bool(num1 and num2)
True
or If any of the two operands are True, >>> True or True
then condition True
becomes True
not Used to reverse the logicalstate of its >>> num1 = 10
operand >>> bool(num1)
True
>>> not num1
>>> bool(num1)
False
Note:
int(): Used to convert string data type to integer.
float():to convert string data type to a floating-point number.