Python Imp
Python Imp
Python is an interpreted , object oriented , most popular and high level programming
language.
It was designed by “Guido Van Rassom” in 1991 and it was developed by “Python
Software Foundation”.
• Extensible Feature:
Collections in python are basically container data types, namely lists, sets,
tuples, dictionary
• List
• Tuple
• Dic
o Dictionary is a collection data type which we represent {}
o Dictionary which is unorderable , indexable ,and mutable
o Dictionary does not allow duplicate value
o It can be store members details in ‘key’ and ‘value’.
o Syntax
Dic_name = {“key”:”value”}
• Set
o Set is a collection data type which is a represent a group of unique value as a single
entity
o Set which is represent by { }
o no orderable and index & slicing not work
o set which is mutable
syntax:
o set = {"item1","item2"}
4. Explain difference between list and tuple
both are collection data type - list which is represent by [] braces when tuple are
represnt by () braces .
list is orderable, indexable but mutable when tuple is orderable ,indexable but
immutable
A Python identifier is a name used to identify a variable, function, class, module or other
object
A lambda function can take any number of argument , but can only have one expression.
Syntax :
Examaple
X = Lambda a:a+10
Print(x(20))
9. What is slicing?
Slicing is a mechanism used to select a range of item from sequence
type like list , tuple , string etc…
The index of the last character will be the length of the string minus one
Exa.
str = "Androidpython.java"
print(str[-1])
• Append() :- using appeend method we can store single element in existing list
• Extend() :- using of extends method we can store more than one element in existing list (in
the form of list)
negative indexes is used to in python to beging slicing from end of the string.
15.What are the rules for local and global variables in python?
• Global : Variables that are created outside of a function (as in all of the examples above) are
known as global variables. Global variables can be used by everyone, both inside of functions and
outside.
• Local : A variable created inside a function belongs to the local variable of that
function, and can only be used inside that function.
16.Explain categories of functions in python
• function without parameter and function without return type
• function with parameter and function without return type
• function without parameter and function with return type
• function with parameter and function with return type
• The format() method formats the specified value(s) and insert them
inside the string's placeholder.
1) Arithmetic operator :-
Arithmetic operators are used to perform mathematical operations like
addition, subtraction, multiplication, etc. For example, (+,-,*,/,//,%,**)
num1 = 10
num2 = 20
print(num1 + num2)
# assign 5 to x
var x = 5
shorthand operator :
when we use arithmetic and assignment same time its called shorthand operator
a=10
b=20
a += b
print(a)
a=5
b =2
print (a > b) # True
Operator Meaning Example
4) Logical Operators :-
Here, and is the logical operator AND. Since both a>2 and b >= 6 are True , the
result is True .
Logical AND:
and a and b
True only if both the operands are True
Logical OR:
or a or b
True if at least one of the operands is True
Logical NOT:
not not a
True if the operand is False and vice-versa.
5) Bitwise operators :-
Bitwise operators act on operands as if they were strings of binary digits. They operate
bit by bit, hence the name.
6) Membership operators :-
In Python, IN and not in are the membership operators. They are used to test
whether a value or variable is found in a sequence
(string, list, tuple, set and dictionary).
In a dictionary we can only test for presence of key, not the value.
Output
True
True
True
False
print(x)
Output :-
['hello', 'my name is Peter', 'I am 26 years old']
Usually there are 32 keyword And which is based on respective programming language
Example
cap = "python devloper"
print(cap.capitalize())
print(cap)
Output
Python devloper
python developer
Example :-
num = [5,3,2,8,1,0]
num.sort()
print(num)
25.What is the function? difference between function and method
function : function is a block of code - piece of code
function which is provide reusabilities and using of function we can call same code many
times and reduce our code
.append(), .extend()=>method
Function Method
A function is block of code that is called by A method is bock of code that is called by a
name name
It is not associated with an any object It is associated with an object
Free(free means not belong to an object or Mmber(a member of an object or class)
class)
if import in is
yield
Syntax :
datetime.now()
Example :
1. import datetime
2. dt = datetime.datetime.now() # use now() method in datetime
3. print( "Display the current date of the system: ") # current date
4. print (str (dt) ) # call the dt variable to print the system date.
Output:
e.g.
1) women
o Wife
o Daughter
o Student
o Employee
o Mother