Experiment No 1 Python
Experiment No 1 Python
Experiment No 1 Python
Date of Performance :
Date of Submission :
THEORY:
Python Keywords
Keywords are the reserved words in Python. We cannot use a keyword as a variable name, function
name or any other identifier. They are used to define the syntax and structure of the Python
language. In Python, keywords are case sensitive.
Keywords in Python
False Class finally Is return
None Continue for lambda try
True Def from nonlocal while
and Del global not with
as elif if or yield
assert else import pass
break except in raise
Python Identifiers
An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate
one entity from another.
Rules for writing identifiers
1. 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.
2. An identifier cannot start with a digit. 1variable is invalid, but variable1 is perfectly fine.
3. Keywords cannot be used as identifiers.
Python Comments
In Python, the hash (#) symbol to start writing a comment. It extends up to the newline character.
Comments are for programmers for better understanding of a program. Python Interpreter ignores
comment.
Multi-line comments
If we have comments that extend multiple lines, one way of doing it is to use hash (#) in the
beginning of each line. For example: Another way of doing this is to use triple quotes, either ''' or
""".
Python Variables
A variable is a named location used to store data in the memory. It is helpful to think of variables as
a container that holds data which can be changed later throughout programming.
Rules and Naming Convention for Variables and constants
1. Constant and variable names should have a combination of letters in lowercase (a to z) or uppercase
(A to Z) or digits (0 to 9) or an underscore (_). For example:
2. snake_case
3. MACRO_CASE
4. camelCase
5. CapWords
Type Conversion:
The process of converting the value of one data type (integer, string, float, etc.) to another data type
is called type conversion. Python has two types of type conversion.
1. Implicit Type Conversion
2. Explicit Type Conversion
Operators
Operators are special symbols in Python that carry out arithmetic or logical computation. The value
that the operator operates on is called the operand.
Arithmetic operators
Logical operators
a) Write a python program to input student details and display welcome message to newly added
student record.
INPUT:
print("\nWELCOME,",name+"!!")
OUTPUT:
OUTPUT:
print("Password
Length Checker
!!") user_input =
input("Enter a
password : ")
if (len(user_input)<8 or len(user_input)>12):
print("Not valid ! Total characters should
be between 8 and 12 !") else:
print("Password is valid !")
print("Length of Password :",len(user_input))
OUTPUT:
R1 R2 R3 R4 Total Signature
(3 Marks) (3 Marks) (3 Marks) (1 Mark) (10 Marks)