Introduction Flashcards

1
Q

Data Types

  1. How many data types are there in python
A

There are 8 data types, they are:

  1. Integer - int
  2. Floating Point - float
  3. String - str
  4. Lists - list
  5. Dictionary - dict
  6. Tuples - tup
  7. Sets - set
  8. Booleans - bool
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Data Types

  1. Integer
A

Whole Numbers, positive or negative

Example:
- 2 444 66

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

Data Types

  1. Floating Point
A

Decimal numbers eg. 2.3 33.0 0.009

Apart from using decimal point they also sometimes use Exponential (E)
\ (e) to define the number.

For example: 4E2 (4 times 10 to the power of 2)

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

Data Types

  1. String
A

Ordered sequence of Characters- ‘‘hello’’ ‘999’ “34ndj”

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

Data Types

  1. Lists
A

Ordered sequence of Objects - [“apple”, 10, 1.24]

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

Data Types

  1. Dictionaries
A

Unordered Key, value pairs - {“mykey”: “value”, “name”: “franky”}

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

Data Types

  1. Tuples
A

Ordered immutable sequence of objects -
( 10, “hello”, 200.3)

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

Data Types

  1. Sets
A

Unordered collection of unique objects - {“a”, “b”}

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

Data Types

  1. Booleans
A

Logical Value indicating - True or False

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

Data Types

  1. What do you mean by data types?
A

Data type is a classification that specifies which type of value a variable has.

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

Data type

  1. What is a variable in python?
A

i. A python variable is a symbolic name that is a reference or pointer to an object.

ii. Once an object is assigned to a variable, one can refer to the object by that name.

iii. But the data itself is still contained within the object. For example

n = 300

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

Data type

Numbers

  1. What are the Arithmetic Operators?
A

Addition +

Subtraction. -

Multiplication *

Division /

Floor Division. //

( eg. 7 // 4 = 1 . The // operator (two forward slashes) truncates the decimal without rounding, and returns an integer result)

.Power **

Mod %

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

Data type

  1. ________ Brings back reminder after division
A

Modulo or Mod operator

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

Data type

  1. This is used to check whether a number is even or odd, for instance to find 23%2 is even or odd? If the result is 0 its not even. Which arithmetic operator is used?
A

Modulo or Mod

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

Data type

  1. What is the difference between floating point and an integer?
A

Integer - Whole Number
Floating point - Decimal Number

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

Variable Assignments

Variable Assignments

  1. What are the rules followed in naming variables?
A

i. Names can’t start with number

ii. No spaces in the name, _ can be used instead

iii. Can’t use symbols like - : “” ‘’ , <> | \ ? / () ! @ # $ % ^ & * ~ - +

iv. Use lowercase (according to PEP8)

v. Avoid Special Meaning words like “list”, “str”, ect.,

vi. Avoid using ( L ) , ( O ) , ( I ) because they can mistook as 1 and 0

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

Data type

  1. Python uses _____ typing
A

Dynamic

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

Data type

  1. What is Dynamic Typing? and What are the pros and cons of dynamic typing?
A

Dynamic typing enables to reassign variables to different data types.

  • Pros of Dynamic Typing
    1. very easy to work with
    2. faster development time
  • Cons of Dynamic Typing
    1. may result in unexpected bugs!
    2. you need to be aware of type()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

String

Assigning and Reassigning

i. For the variable assignment ___ assignment operator is used. an example ___

ii. What command should be applied, to find a Type of a variable?

A

i. = , name = object

ii. type( variable name )

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

String

  1. What is a String?
A

Strings - Ordered Sequences of Characters, which means Indexing and Slicing can be done to grab sub-sections of the string
- Using Syntax of ‘ ‘or “ “
- Example: ‘hello’, “hello”, “I don’t do that”

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

String

  1. What are the features Indexing ?
A
  • Uses [ ] notation after the string
  • Grabs single character from the string
  • Every single character is assigned with a number
    For Instance:

Character : H E L L O
Index : 0 1 2 3 4
Reverse Index : 0 -4 -3 -2 -1

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

String

  1. What is Slicing?
A

Slicing - Grabs a subsection of multiple characters
i.e. A “Slice of a string”

  • [Start:Stop:Step]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  1. Define Start , Stop , Step?
A

Start - Numerical index for the slice Start

Stop - The index u will go uptown but not include

Step - Size of the ‘Jump’ u take

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

String

  1. How to apply Print Function?
A

The commons has taken out the double quotes and given the output

print (“Hello World”)

Hello World

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

String

  1. What if “Hello World” is typed in directly without using print( )?
A

IN : “Hello World”
OUT : “Hello World”

output comes as it was typed in

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

Strings

  1. ESCAPE SEQUENCE
A

\n

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

String

  1. How to run the Escape Sequence?
A

IN : print ( ‘Hello\nWorld’ )

OUT : Hello
World

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

String

  1. How to run TAB command ?
A

gives 4 spaces between the words

  • \t

IN : print (‘Hello\tworld”)

Out: Hello World

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

String

  1. LENGTH FUNCTION
A
  • len
  • outputs length of the string
  • len( ‘hello’ )
  • OUT: 5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

String

  1. In length function ______ is counted as a character.
A

Space

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

String

String Indexing and Slicing

  1. ________ grabs single characters from a string.
A

String Indexing

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

String

  1. name. = “Sam”
    name[0] = ‘P’

Can’t do this for a string because strings are _______.

A

Immutable

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

String

  1. Merging two strings together are called __________.
A

Concatenation

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

String

  1. Give an example for concatenation.
A

last_letters = ‘am’
‘P’ + last_letters

OUT : ‘Pam’

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

String

  1. How to run multiple concatenation?
A

letter = ‘A’
letter * 10

OUT : ‘ AAAAAAAAAA’

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

String

  1. To get Methods and attributes on Jupiter notebook, _______ is to be clicked.
A

Tab

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

String

  1. Are strings mutable?
A

Strings are not mutable (meaning it cannot use indexing to change individual elements of a string)

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

String

  1. How to create comments in of a code?
A

Using #HASTAG

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

String

Print Formatting and Strings

  1. What is Interpolation? And what are the methods involved in Print Formatting?
A

Interpolation is mostly used to in put missing values in the data-frame or series while preprocessing data.

There are three methods. - .format()method
- f-strings (formatted strin literals)
- % modulo
CURRENTLY NOT USED:
(The oldest method involves placeholders using the modulo % character. You can use %s to inject strings into your print statements. The modulo % is referred to as a “string formatting operator”. eg.)

print(“I’m going to inject %s here.” %’something’)

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

String

  1. What is the purpose of .format( )method and write the syntax?
A

To add formatted objects to printed string statements.

‘String { }’ .format ( ‘something1’, ‘something2’)

41
Q

String

  1. An example for .format( ) method.
A

print ( ‘ Hello World { } ‘ .format ( ‘ New Earth’ ) )

42
Q

String

  1. Indexing in .format( ) method , example.
A

print (‘The {2} {1} {0}’ .format (‘fox’,’brown’,’quick’) )

43
Q

String

  1. Assigning Keywords for .format ( ) , example.
A

print (‘The {q} {b} {f}’ .format (f=’fox’,b=’brown’,q=’quick’) )

44
Q

String

  1. Syntax of f - strings.
A

Syntax : “{ value : width .precision f}”

45
Q

String

  1. Example : Float Formated / f-string
A

name = “ Sam “
age = 3

print ( f ‘ {name} is {age} years old’ )

OUT : Sam is 3 years old

46
Q

Lists

  1. Write a note on Lists?
A
  1. Lists are Ordered sequences - can hold different object types
  2. Brackets and Commans are used eg. [1,2,3,4,5]
  3. Supports Indexing, Slicing and Concatenation
  4. Can be nested and. also have a variety of useful methods that can be called off of them.
  5. Can mutate, change or resign
47
Q
  1. .append ( )
A

Allows to add a new element to the list.

48
Q
  1. .pop ( )
A

Removing an last item from the list.

49
Q
  1. Can an item be removed from a list at any index point?
A

Yes, by using indexing

item = [ ‘apple’, ‘orange’, ‘mangoes,]

item.pop(2)

[‘apple’,’orange’]

50
Q

Lists , built in methods

Write few elements that are used in list?

A
  1. .append ( )
  2. .pop ( )
  3. .sort ( )
  4. .reverse ( )
51
Q

String, built in method

  1. Give an example :
    - .split ( ) (two methods)
  • .upper ( )
A

x = ‘Hello World’
x.split( )

OUT: [‘Hello’ , ‘World’]

x.split ( l )

OUT: [‘He’, ‘’, ‘o Wor’, ‘d’]

(#coverts string into a list)

x.upper ( )

OUT : ‘HELLO WORLD’

52
Q

Dictionaries
52. Write a note on dictionaries?

A
  1. Dic are Unordered mappings of storing objects - Key value mapping means that its going to insert key value pairs where ever it is most efficient
  2. Dic use Key-Value pairing to store data objects
  3. Without the need to know the index location, key-value pairs allows user
  4. Dic use Curly Braces and Colons to signify the keys and their associated values
    eg. {‘key1’:’value1’,’key2’:’value2’}
53
Q
  1. When to choose dictionary over list?
A

When quickly needed to retrieve an item without knowing the index location.

54
Q
  1. Objects retrieved by key name -
    Objects retrieved by location -
A

Dictionaries

Lists

55
Q
  1. ____ sequence can be Indexed or Sliced.
A

Ordered Sequence

56
Q
  1. Syntax of Dictionary
A

{“mykey1” : “value”, “mykey2” : “value”}

57
Q
  1. Give an example for dictionary.
A

prices_lookup = {‘apple’: 2.99, ‘oranges’: 1.99, ‘milk’ : 5.80}

prices_lookup [‘apple’]

OUT: 2.99

58
Q
  1. Give an example to understand, how list is associated within dictionary and Indexing?
A

d = {‘k1’: 123, ‘k2’: [0, 1, 2, 3], ‘k3’:{‘insidekey’: 100}}

d[‘k3’][‘insidekey’]

OUT: 100

Indexing

d[‘k2’] [1]

OUT: 1

59
Q
  1. Give example : Changing the letter C to uppercase in dictionary.
A

dd = {‘key1’: [‘a’,’b’,’c’]}
dd

Out:

mylist = dd[‘key1’]
mylist

OUT:

letter = mylist[2]
letter

OUT:

letter.upper( )

OUT: ‘C’

60
Q
  1. Give example : Changing the letter C to uppercase in dictionary. In Single step.
A

dd [‘key1’] [2] .upper( )

OUT: ‘C’

61
Q
  1. Adding a new key value pair to the dictionary.
A

d ={‘k1’:100,’k2’:200}
d

OUT:

d[‘k3’]=300
d

OUT: {‘k1’: 100, ‘k2’: 200, ‘k3’: 300}

62
Q
  1. In dict, just needed to know the keys of the values.
A

.keys( )

63
Q
  1. In dict, just needed to Values of the key.
A

.values ( )

64
Q
  1. In dict, to see the pairs together.
A

.items( )

The results will be in parenthesis and this is called Tuples.

65
Q

Tuples

  1. Write a note on Tuples?
A
  1. Tuples are like lists but they are Immutable
  2. Once an element is inside a tuple, it cannot be reassigned
  3. Tuples use Parenthesis : eg. (123)
  4. Can execute multiple commands like len, Indexing and Count be done.
66
Q
  1. What is .count( ) ?
A

Count gives how many times an element in the tuple is present.

example:

t = (‘a’, ‘a’, ‘c’)
t.count(‘a’)

OUT: 2

67
Q
  1. In tuple, .index( )
A

Show the elements index where it appeared for the 1st time.

68
Q
  1. When tuple is used?
A

Tuple is used when u are passing around objects and don’t accidentally change.

69
Q

Sets

  1. Define sets.
A

Sets are unordered collections of unique elements i.e. there can only be one representative of the same object.

70
Q
  1. Adding an object to the set
A

myset = set( )

myset

OUT: set( )

myset.add(‘apple’)
myset

OUT: {‘apple’}

myset.add(‘apple)
myset

OUT : {‘apple’} #comes the same, no two same values can be added in set.

71
Q
  1. Having multiple values in set.
A

my list = [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3]
set(mylist)

OUT: {1, 2, 3}

72
Q

Booleans

  1. Define Booleans.
A
  1. Booleans are operators that allow you to convey True or False statements.
  2. These are very important when dealing with control flow and logic
73
Q

In booleans True and False , first letters should be in ____ letter.

A

Capital

74
Q
  1. Example for Boolean.
A

1 > 2

OUT: False

1 == 1

OUT: True

75
Q
  1. ____ function is used as a place holder
A

None

76
Q

a = 10
a + a
OUT: 20

Reassigning:

a = a + a
OUT: 20

Using arithmetic operator addition:

a += 10

What is the output?

A

OUT: 30

77
Q
  1. %s
A

%s operator converts whatever it sees into a string, including integers and floats.

78
Q
  1. %d
A

%d operator converts numbers to integers first, without rounding.

79
Q
  1. %r
A

%r and repr() deliver the string representation of the object, including quotation marks and any escape characters.

80
Q

String and List

Python’s built-in len( ) function counts all of the characters in the string, including ____ and ____

A

Spaces and Punctuation

81
Q

Strings

Strings are a ______

A

Sequence

82
Q

Strings Indexing

For indexing ______ notation is used

A

[ ]

83
Q

String , Indexing

Indexing starts at ____ index

A

0

84
Q

String, Slicing

___ is used to perform slicing which can gran everything up-to a designated point

A

:

85
Q

String , Slicing

How to print a string backwards using slicing ?

eg: ‘Hello World’

A

s = ‘Hello World’

s[ : : -1 ]

OUTPUT: ‘dlroW olleH’

86
Q

String , Slicing

Grab everything past the first term all the way to the length of s

s = ‘Hello World’

A

s[ 1: ]

OUTPUT: ‘ello World’

87
Q

String, Slicing

S = “Hello World”

Grab everything up to the 3rd index

A

s[ : 3 ]

88
Q

String , Slicing

s = ‘Hello World’

Grab everything

A

s[ : ]

89
Q

String , Reverse Indexing

Grab everything but the last letter

s = ‘Hello World’

A

s[ : -1 ]

90
Q

String , Slicing

s = ‘Hello World’

Grab everything, but go in step size of 2

A

[ : : -2 ]

91
Q

String

Strings have an important property known as ____.

A

Immutability

92
Q

String

What is Immutability?

A

Once a string is created, the elements within it can not be changed or replaced.

eg.

s = ‘Akshita’

s[0] = ‘R’

OUTPUT: ERROR

93
Q

Strings , Built in methods

Give few built in methods of a String.

A

.upper ( )
.lower ( )
.split ( )

There are many more methods

94
Q

String , Print Formatting

_____ method is used to add formatted objects to printed string statements.

A

.format( )

95
Q

String, Print formatting

Give an example for .format( )

A

‘Insert curly brackets { }’.format(‘to the string’)

Output: ‘Insert curly brackets to the string

96
Q

Lists

Can concatenation applied on lists

A

yes, Concatenation can be applied to lists merging to lists together.

97
Q

An advanced feature of list is called _______

A

List Comprehension

98
Q

_________ allow for quick construction of lists.

A

List Comprehension