Python Practical No.
1
Q.Introduction to python and python datatypes.
1) Installation of python
2) Values and types:
(int , float, string)
Int: Int comes under the numeric datatype, it is show the given number is whole
(example: a=8
print(type(a))
>>int)
Float: Float comes under the numeric datatype, it is show the given number is decimal
(example: a=8.8
print(type(a))
>>float)
String:It is used for characters
(example: a=”sagar”
print(type(a))
>>str)
3) Variables:
(Variables, printing variable values ,types of variables)
=>A Python variable is a reserved memory location to store values. In other words, a
variable in a python program gives data to the computer for processing.
=>Variables can be declared by any name or even alphabets like a, aa, abc, etc.
=>Variable Naming Rules in Python
1. Variable name should start with letter(a-zA-Z) or underscore (_).
2.In variable name, no special characters allowed other than underscore (_).
3.Variables are case sensitive.
4.Variable name can have numbers but not at the beginning.
5.Variable name should not be a Python keyword.
4) Operators, operands and precedence
( “+“ , ”- “, “*” , “/ “, ”** “, ”%”)
Addition (+): Adds two numbers together.
Subtraction (-): Subtracts one number from another.
Multiplication (*): Multiplies two numbers together.
Division (/): Divides one number by another, producing a float result.
Modulus (%): Returns the remainder after dividing one number by another.
Exponentiation (**) : Raises a number to a power.
5) String operations:
(concatenation ,repetition)
=>In Python, strings are used for representing textual data. A string is a sequence of
characters enclosed in either single quotes ('') or double quotes (“”).
=>String concatenation is a common operation in programming. It involves joining two or
more strings to create a single new string.
=>The simplest way to repeat a string in Python is with the * operator. Use the operator on a
string to repeat the string a provided number of times.
6) Comparison operators
( “==” , “!=” ,”<=” , “>=” )
=>Python provides several comparison operators:
==: Equal to
!=: Not equal to
>: Greater than
<: Less than
>=: Greater than or equal to
<=: Less than or equal to
7) Logical operators
( and , or , not )
=>Python has three logical operators:
and: Returns True if both operands are True.
or: Returns True if at least one operand is True.
not: Inverts the truth value of the operand.