Introduction Flashcards
(53 cards)
Two main reason to choose Python?
- Code Readability
2. Developer Productivity
What type of programming language Python is?
- General programming language
- Scripting programming language
- Functional programming language
- Object Oriented programming language
What’s the execution flow of python code?
- Source code (.py)
- __pycache__
- Python Virtual Machine (PVM)
What are different implementation of Python?
- cpython
- jython
- iron python
- pypy
- stackless
What are frozen binaries in Python?
Python byte codes with Python interpreter, hence no environment setup is required for same.
How to decompose a python program?
Modules
- statements
- expressions
- – objects
- expressions
- statements
Is Python strongly typed? If yes, how?
yes, it provides datatype to each of it’s variables. There is not variable without datatype.
Is Python Dynamically typed language? If yes, how?
yes it is dynamically typed.
In this interpreter provides “type” to a variable during runtime, based on the variable’s value at that time.
What’s the relation between objects and expressions?
Expressions are used to created Objects
How variables created in Python?
When we assign a value to it
How to add multiple expressions in a single line in Python interactive?
By using “comma”.
How to add single line comment in Python scripts?
By using #
Given an example of chained comparision?
a < b < c
What’s the result for following expression:
a. 9/3
b. 9.0/3
c. 5//-2
d. 5//-2.0
a. 9/3 = 3
b. 9.0/3 = 3.0
c. 5//-2 = -3
d. 5//-2.0 = -3
How to represent data in :
- HexaDecimal
- Octal
- Binary
- HexaDecimal: 0x234
- Octal: 0o234
- Binary: 0b11001
Name function to convert an integer into
- Hexadecimal
- Octal
- Binary
hex()
oct()
bin()
how to convert base value to int?
int(baseValue, base)
e.g. int(0x345, 16)
int(0o76, 8)
int(0b11011, 2)
Built-in function for calculation of power of decimal number?
pow()
pow(2,6)
Built-int function for calculation of
- Power
- maximum
- minimum
- integer
- rounding upto decimal place
- summation
- absolute value
- Power = pow(2,6)
- maximum = max()
- minimum = min()
- integer = int()
- rounding upto decimal place = round(23.445,2)
- summation = sum([])
- absolute value = abs()
Math module common function:
- Get pi Value
- Get e value
- Calculate square root
- Calculate floor value
- Calculate truncate value
- Calculate, sin, cos, tan
- Get pi Value = math.pi
- Get e value = math.e
- Calculate square root = math.sqrt()
- Calculate floor value = math.floor()
- Calculate truncate value = math.trunc()
- Calculate, sin, cos, tan = math.sin(), math.cos(), math.tan()
Random module common function:
- Get a random float value
- Get a random int value
- Shuffle a list
- Get a choice from the list
Random module common function:
- Get a random float value: random.random()
- Get a random int value: random.randint(1,1000)
- Shuffle a list: random.shuffle([])
- Get a choice from the list: random.choice([])
What are sets ?
Sets are nothing but the “value less dictionaries”. (means they have only keys”, with following properties:
- Unordered
- Unique
- iterable
Can we add lists and dictionaries in sets?
No, because both of Mutable.
Only those objects can be stored in set, which are immutable and hasable.
How to create set in Python
- By function name = set()
2. By Curly braces = {a,b,c,d}