Python 3 Programming
Python 3 Programming
Introduction to Python
Python is a high-level, interpreted, interactive and object-oriented scripting language which
finds its application in many areas like -
Webscripting
3d Modelling (Blender)
Desktop Applications -`Games (Pygame)
Scientific usage (SciPy/NumPy)
Python source code is available under the GNU General Public License (GPL). There are
two major Python versions, Python 2 and Python 3.
Python features
Object-oriented (supports both functional and structured programming)
Dynamically and strongly typed
Whitespace delimited (Indentation)
Scripting language which supports large applications.
High-level dynamic data types and supports dynamic type checking
Automatic garbage collection
Interpreted makes compiler interact with developer.
Easy integration with C, C++, COM, ActiveX, CORBA and Java.
Python Implementations
CPython - Python implementation on standard C language.
Jython - Python implementation with Java virtual machine to blend with Java.
Pypy - Python implemented in Python and its Just-in time compiler making it fastest.
Iron Python - for windows, which implements common runtime libraries to interface
with .NET.
Print:
Integer Division:
Python 2 treats numbers without any digits. (Output of expression 3 / 2 is 1, not 1.5).
To get the result 1.5, you would have to write 3.0 / 2.0.
Python 3 evaluates 3 / 2 as 1.5 by default, which is more intuitive for new
programmers.
List Comprehension Loop Variables: Common name for the variables that is iterated over
in a list comprehension as a global variable get interchanged. This is fixed in Python 3.
Hands-0n
#1
#Hands-on - Print
#Write a script to print "Welcome to Python 3".
print('Welcome to Python\' 3')
#2
#Hands-on - Range
#Write script to print the values 0 1 2 3 4. Hint: Use 'range' function and 'for'
loop
#3
#Hands-on - Namespaces
#Write the syntax to list the namespaces inside Python by default.
print(dir())
https://www.programiz.com/python-programming/namespace
1. Which of these are salient features of Python, except? limited platform support
6. Which of the following attributes shows the characteristics of Python? Python is everywhere
(Webscripting, 3D Modelling , Games , and Desktop applications ) ubiquity
8. When using the Python shell and code block, what triggers the interpreter to begin evaluating block of
code.- Blank line
9. While using Python IDLE, by how many space are the code suites indented - 4
10. What command is used to output text from both the Python shell and within a Python module? -
print()
11. Which action should be avoided so that you do not mistakenly overwrite names that you have already
defined? - use wildcraft import
12. The bool class is subset of _____ - int
13. While using 'bool', all zero values are considered as false and non- zero values are considered as true. Is
this correct? - True
14. Which of the following will not result in declaring x as datatype of float? - x=5
19. Which statement accurately defines the bool class - boolan not returns false if operand is true
22. Which statement creates the bytes literal when run? - bytes_literal = b'Copyright \xc2\xa9'
28. Which statements prevent the escape sequence interpretation? r' col
29. The class which provides immutable sequence of elements string w list
31. What is the output of below code snippet - for char in 'Welcome': print (char, end='*') print() -
W*e*l*c*o*m*e*
32. What is the output of the following code count = 0 while count < 2: print (count, " is less than 2") count
= count + 2 else: print (count, " is not less than 2")- 0 is less than 2; 2 is not less than 2
33. What is the output of the following code? for x in (1,10,100): print (x) - 1 10 100
34. bytearray provides an mutable sequence (making it modifiable) - True
35. Which methods can be used with list objects reverse pop clear
36. Which of these could be used in tuple object - Sorted, Lens , Max
37. Byte datatype can contain only ______ and ______. decimal and hexidecimal , ascii and hexidecimal ,
unicode alone(wrong),accii and unicode --correct
38. Which describes bytearrays? - Without an argument , array of size 0 is created , contain a sequence of
integers 0-255
42. Consider b is frozen set, what happen to b.add(3)? - Error as frozen sets cannot be modified
43. Dictionary could be copied to another dictionary using which of following syntax? -
dict_a=dict_b.copy()
44. All of these range types are correct except ___. - range(20,40,-2)
45. In what format does the input function read the user input ? string
46. a = -10 if a: print("a's value") else: print("Sorry nothing will get printed")- Sorry nothing will get printed
48. The default decode option available in the byte data type is - ascii x,
49. Which of these is Desktop applications is created using Python -Drop box