Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3K views

Python 3 Programming

Uploaded by

Mahesh VP
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views

Python 3 Programming

Uploaded by

Mahesh VP
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

 Open Source and Simple to use


 Very powerful and Ubiquitous
 Supports broad standard library
 Supports interactive testing and debugging
 Established interface with all major DB's
 Runs on variety of hardware platforms
Technical features of Python

 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.

Difference between Python2 & Python3

Print:

 Python 2 treats “print” as statement rather a function.


 Python 3 explicitly treats “print” as a function.

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.

Unicode Strings: By default Python 3 stores strings as Unicode unlike Python 2.

Raising Exceptions: Python 3 requires different syntax for raising exceptions.


 Python 2:raise IOError, “some error message”
 Python3: raise IOError(“some error message”)

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

for index in range(0,5):


print(index, end=" ")
print()

#3
#Hands-on - Namespaces
#Write the syntax to list the namespaces inside Python by default.

print(dir())

https://www.programiz.com/python-programming/namespace

Modules and Imports


Radius calculation :

1. Which of these are salient features of Python, except? limited platform support

2. Code written in Python 3 is backward compatible with Python 2 - False

3. Which is the fastest implementation of Python? - pypy

4. Python supports automatic garbage collection.- True

5. Python is Ubiquitous? Is this true or false -True

6. Which of the following attributes shows the characteristics of Python? Python is everywhere
(Webscripting, 3D Modelling , Games , and Desktop applications ) ubiquity

7. The 2 main versions of Python include - python 2x and 3x

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

15. Is x,y=5,6 a valid statement? - True

16. Which statement correctly assigns X as an infinite number? - x=float('inf')

17. What is the output of bool(0)? F

18. Equivalent operation for function pow(x , y) is __. - x ** y

19. Which statement accurately defines the bool class - boolan not returns false if operand is true

20. Empty list could be created with list() alone. F

21. Values in bytearray should be integers between 0-255

22. Which statement creates the bytes literal when run? - bytes_literal = b'Copyright \xc2\xa9'

23. What is the output of max('Infinity')? Y(Wrong)

24. While using slicing in lists, list[0:2] is equivalent to ______. -list[:2]

25. What is the output of min('Infinity')? i

26. Which statements will result in slice of tuple? a_tuple[::2]a_tuple[:]

27. Empty list could be created with list() alone.F

28. Which statements prevent the escape sequence interpretation? r' col

29. The class which provides immutable sequence of elements string w list

30. Using Pop in list will remove the popped up item. T

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

39. Empty dictionary is represented as ________.- {}

40. a.symmetric_difference(b) highlights the ________.- a union(b)-a.intersection(b)

41. a.difference(b) highlights the ________. - a - b

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

47. What is the output of - list_pt = list('Welcome') print(list_pt) - Welcome x,

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

You might also like