Introduction Flashcards

(53 cards)

1
Q

Two main reason to choose Python?

A
  1. Code Readability

2. Developer Productivity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What type of programming language Python is?

A
  1. General programming language
  2. Scripting programming language
  3. Functional programming language
  4. Object Oriented programming language
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the execution flow of python code?

A
  1. Source code (.py)
  2. __pycache__
  3. Python Virtual Machine (PVM)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are different implementation of Python?

A
  1. cpython
  2. jython
  3. iron python
  4. pypy
  5. stackless
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are frozen binaries in Python?

A

Python byte codes with Python interpreter, hence no environment setup is required for same.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to decompose a python program?

A

Modules

    • statements
        • expressions
          • – objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is Python strongly typed? If yes, how?

A

yes, it provides datatype to each of it’s variables. There is not variable without datatype.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is Python Dynamically typed language? If yes, how?

A

yes it is dynamically typed.

In this interpreter provides “type” to a variable during runtime, based on the variable’s value at that time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the relation between objects and expressions?

A

Expressions are used to created Objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How variables created in Python?

A

When we assign a value to it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to add multiple expressions in a single line in Python interactive?

A

By using “comma”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to add single line comment in Python scripts?

A

By using #

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Given an example of chained comparision?

A

a < b < c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s the result for following expression:

a. 9/3
b. 9.0/3
c. 5//-2
d. 5//-2.0

A

a. 9/3 = 3
b. 9.0/3 = 3.0
c. 5//-2 = -3
d. 5//-2.0 = -3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to represent data in :

  1. HexaDecimal
  2. Octal
  3. Binary
A
  1. HexaDecimal: 0x234
  2. Octal: 0o234
  3. Binary: 0b11001
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Name function to convert an integer into

  1. Hexadecimal
  2. Octal
  3. Binary
A

hex()
oct()
bin()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how to convert base value to int?

A

int(baseValue, base)
e.g. int(0x345, 16)
int(0o76, 8)
int(0b11011, 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Built-in function for calculation of power of decimal number?

A

pow()

pow(2,6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Built-int function for calculation of

  1. Power
  2. maximum
  3. minimum
  4. integer
  5. rounding upto decimal place
  6. summation
  7. absolute value
A
  1. Power = pow(2,6)
  2. maximum = max()
  3. minimum = min()
  4. integer = int()
  5. rounding upto decimal place = round(23.445,2)
  6. summation = sum([])
  7. absolute value = abs()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Math module common function:

  1. Get pi Value
  2. Get e value
  3. Calculate square root
  4. Calculate floor value
  5. Calculate truncate value
  6. Calculate, sin, cos, tan
A
  1. Get pi Value = math.pi
  2. Get e value = math.e
  3. Calculate square root = math.sqrt()
  4. Calculate floor value = math.floor()
  5. Calculate truncate value = math.trunc()
  6. Calculate, sin, cos, tan = math.sin(), math.cos(), math.tan()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Random module common function:

  1. Get a random float value
  2. Get a random int value
  3. Shuffle a list
  4. Get a choice from the list
A

Random module common function:

  1. Get a random float value: random.random()
  2. Get a random int value: random.randint(1,1000)
  3. Shuffle a list: random.shuffle([])
  4. Get a choice from the list: random.choice([])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are sets ?

A

Sets are nothing but the “value less dictionaries”. (means they have only keys”, with following properties:

  1. Unordered
  2. Unique
  3. iterable
23
Q

Can we add lists and dictionaries in sets?

A

No, because both of Mutable.

Only those objects can be stored in set, which are immutable and hasable.

24
Q

How to create set in Python

A
  1. By function name = set()

2. By Curly braces = {a,b,c,d}

25
Provide following set operations by expressions and functions: 1. Union 2. Intersection
1. Union >> a.union(b) >> a | b | 2. Intersection >> a.intersection(b) >> a & b
26
How to add an item inside a set?
a = set() | a.add(234)
27
How to remove an item from a set
a = set() | a.remove(34)
28
How to find one set is subset of another?
a = set() b = set() a.issubset(b)
29
Does variable contains the absolute or literal value in Python?
No, variables are just references in Python.
30
Is there any primitive type in Python?
No, there is no primitive type in Python. Each and every literal are objects, even numbers.
31
Is type associated by variables in Python?
No, datatypes are not associated with variables. These are just references. Types are always associated with objects.
32
Different steps executed by Python, when we run a = 34?
1. It creates a variable and save same in one location 2. It creates object '34' and save same in another location 3. It creates a reference, (pointer in memory) and link variable and object
33
Is it possible to link or refer one variable by another variable?
No, a variable can only refer an object
34
it is possible to assign a type to a variable?
No, types are always assigned to the objects.
35
How references are implemented in Python?
References are implemented as "pointers" in Python.
36
What are header fields in each objects? What are the main components of header fields?
Header fields contains the "meta-data" about the object. Each header contains following fields: 1. Type Designator field 2. Reference Counter field
37
What are shared references?
References which refers same objects: a = 5 b = a
38
What are shared references of mutable objects
``` a = [1,2,3] b = a b[0] = 23 # This will affect a as well ```
39
What is "copy" module and it's important function?
``` Copy module is used to copy any type of collection. import copy a = [1,2,3] b = copy.copy(a) c = copy.deepcopy(a) ```
40
Which operator is used to compare the "values" of object?
Equality operator: ==
41
Which operator is used to compare the "references" of the object?
"is operator" | a is b
42
How to get the number of references hold by an object?
By using "sys" module | sys.getrefcount(1)
43
What is a string
Ordered collection of characters
44
How to find the length of the string?
len()
45
Does escape sequence works in all types of string representation in Python?
yes, it works with 1. single quote 2. double quote 3. tripple quote
46
What is a raw string? What's it's use case
Raw string is used to disable the "escape" sequence mechanism in different strings. e.g. r'my\path' It is generally used in path
47
What will happen if we add "back slash" at the end of "raw string"?
it will give an error, as we are not allowed to use "odd" number of back slashes in raw string
48
What are strings in triple quotes? What is it's use case?
Triple quote strings are used to create multiline string. | It's use case is to preserve the formatting.
49
Can we use "multiple string" to disable the source code?
Yes, this is generally done by the developers
50
Overloaded operators used for string addition and multiplications?
1. String addition: + | 2. String multiplication: *
51
What is the use case of string multiplication?
To repeat the character when required '_'*80 '---------------------------'
52
How to iterate through character of a string?
s = 'asdfoasdf' for c in s print(c)
53
What's the purpose of in operator?
It is used to search a substring in a string | 'a' in 'asdflajsdf'