Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

List any four core features of python Bytecode

1) Porable 1) It is low level platform independent


2) Interpreted representation of source code
3) Scalable 2) It consists of highly optimized set of machine
4) Extensible instructions interpreted by Python virtual
machine(PVM)

Applications of Python Modes of Running Python scripts


1) GUI 1) Interactive mode
2) Database programming 2) Script mode
3) Internet Access 3) IDLE (Integrated development and learning
4) System programming Environment)
Example for assigning multiple values to Keywords
variables
a,b,c=1,2,3 They are reserved words and cannot be used as
now a=1,b=2,c=3 constants or identifier names.
In Python 2.7-31 keywords
Python 3.6- 33 keywords
Program to display the list of keywords Input function
import keyword It is used for accepting the input from the user
print(keyword.kwlist) Syntax
input(string) where string parameter is
optional
Note: input() by default returns string (> Python
3 version)
Program
a=input("Enter name")
print(a)
Output function (print()) Indentation
It is used to display the data to the standard 1) It identifies which blocks of code a statement
output device. belongs to.
Syntax 2) Python does not support braces to indicate
print(*objects,sep=' blocks of code for classes or function definitions
',end="\n",file=sys.stdout,flush=False) or control flow statements.
#objects are the values to be printed Note: All continuous lines indented with same
Program number of spaces form a block
a=10 Program throwing indentation error
b=20 a=10
c=30 print(a) #now python throws an error since
print(a,b) print() is not correctly indented
print(c)
Output
10 20
30
Note: By default print() inserts space between
values and displays the data in new line
Program to check whether given input is Program to check whether the given variable
keyword or not is identifier or not
import keyword print('a'.isidentifier()) #True
a=input() print('123'.isidentifier()) #False
print(keyword.iskeyword(a))
Output
if
True

int
False
Program explaining usage of multiline Escape sequences
statements using line continuation
character(\)
x="hai "+\ They are mainly used to format the display of the given
"welcome "+\ data
"to cse" Escape sequence characters
1) \' - prints single quote
print(x)
print("what\'s your age")
Output Output
hai welcome to cse what's your age
2) \"-prints double quotes
print("\"hai welcome\"")
Output
"hai welcome"
3) \n – prints newline character
print("hai\ncse")
Output
hai
cse
4)\t- prints tab

Program to display "Hello world" right justified What happens when semicolon is placed at the end
and center-aligned with a width of 20 characters of print statement
print(format("Hello world",">20")) #right justified There will be no error and output will be printed as
Hello world usual
print(format("Hello world","^20")) #center aligned-
displaying Hello world in the center Example
print "hi";
hi

You might also like