Introduction Flashcards

(98 cards)

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
# String 25. What if "Hello World" is typed in directly without using print( )?
IN : "Hello World" OUT : "Hello World" output comes as it was typed in
26
# Strings 26. ESCAPE SEQUENCE
\n
27
# String 27. How to run the Escape Sequence?
IN : print ( 'Hello\nWorld' ) OUT : Hello World
28
# String 28. How to run TAB command ?
- \t IN : print ('Hello\tworld") Out: Hello World #gives 4 spaces between the words
29
# String 29. LENGTH FUNCTION
- len - outputs length of the string - len( 'hello' ) - OUT: 5
30
# String 30. In length function ______ is counted as a character.
Space
31
# String String Indexing and Slicing 31. ________ grabs single characters from a string.
String Indexing
32
# String 32. name. = "Sam" name[0] = 'P' Can't do this for a string because strings are _______.
Immutable
33
# String 33. Merging two strings together are called __________.
Concatenation
34
# String 34. Give an example for concatenation.
last_letters = 'am' 'P' + last_letters OUT : 'Pam'
35
# String 35. How to run multiple concatenation?
letter = 'A' letter * 10 OUT : ' AAAAAAAAAA'
36
# String 36. To get Methods and attributes on Jupiter notebook, _______ is to be clicked.
Tab
37
# String 37. Are strings mutable?
Strings are not mutable (meaning it cannot use indexing to change individual elements of a string)
38
# String 38. How to create comments in of a code?
Using #HASTAG
39
# String Print Formatting and Strings 39. What is Interpolation? And what are the methods involved in Print Formatting?
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')
40
# String 40. What is the purpose of .format( )method and write the syntax?
To add formatted objects to printed string statements. 'String { }' .format ( 'something1', 'something2')
41
# String 41. An example for .format( ) method.
print ( ' Hello World { } ' .format ( ' New Earth' ) )
42
# String 42. Indexing in .format( ) method , example.
print ('The {2} {1} {0}' .format ('fox','brown','quick') )
43
# String 43. Assigning Keywords for .format ( ) , example.
print ('The {q} {b} {f}' .format (f='fox',b='brown',q='quick') )
44
# String 44. Syntax of f - strings.
Syntax : "{ value : width .precision f}"
45
# String 45. Example : Float Formated / f-string
name = " Sam " age = 3 print ( f ' {name} is {age} years old' ) OUT : Sam is 3 years old
46
Lists 46. Write a note on Lists?
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
47. .append ( )
Allows to add a new element to the list.
48
48. .pop ( )
Removing an last item from the list.
49
49. Can an item be removed from a list at any index point?
Yes, by using indexing item = [ 'apple', 'orange', 'mangoes,] item.pop(2) ['apple','orange']
50
# Lists , built in methods Write few elements that are used in list?
1. .append ( ) 2. .pop ( ) 3. .sort ( ) 4. .reverse ( )
51
# String, built in method 51. Give an example : - .split ( ) (two methods) - .upper ( )
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
Dictionaries 52. Write a note on dictionaries?
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
53. When to choose dictionary over list?
When quickly needed to retrieve an item without knowing the index location.
54
54. Objects retrieved by key name - Objects retrieved by location -
Dictionaries Lists
55
55. ____ sequence can be Indexed or Sliced.
Ordered Sequence
56
56. Syntax of Dictionary
{"mykey1" : "value", "mykey2" : "value"}
57
57. Give an example for dictionary.
prices_lookup = {'apple': 2.99, 'oranges': 1.99, 'milk' : 5.80} prices_lookup ['apple'] OUT: 2.99
58
58. Give an example to understand, how list is associated within dictionary and Indexing?
d = {'k1': 123, 'k2': [0, 1, 2, 3], 'k3':{'insidekey': 100}} d['k3']['insidekey'] OUT: 100 Indexing d['k2'] [1] OUT: 1
59
59. Give example : Changing the letter C to uppercase in dictionary.
dd = {'key1': ['a','b','c']} dd Out: mylist = dd['key1'] mylist OUT: letter = mylist[2] letter OUT: letter.upper( ) OUT: 'C'
60
60. Give example : Changing the letter C to uppercase in dictionary. In Single step.
dd ['key1'] [2] .upper( ) OUT: 'C'
61
61. Adding a new key value pair to the dictionary.
d ={'k1':100,'k2':200} d OUT: d['k3']=300 d OUT: {'k1': 100, 'k2': 200, 'k3': 300}
62
62. In dict, just needed to know the keys of the values.
.keys( )
63
63. In dict, just needed to Values of the key.
.values ( )
64
64. In dict, to see the pairs together.
.items( ) The results will be in parenthesis and this is called Tuples.
65
Tuples 65. Write a note on Tuples?
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
66. What is .count( ) ?
Count gives how many times an element in the tuple is present. example: t = ('a', 'a', 'c') t.count('a') OUT: 2
67
67. In tuple, .index( )
Show the elements index where it appeared for the 1st time.
68
68. When tuple is used?
Tuple is used when u are passing around objects and don't accidentally change.
69
Sets 69. Define sets.
Sets are unordered collections of unique elements i.e. there can only be one representative of the same object.
70
70. Adding an object to the set
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
71. Having multiple values in set.
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
Booleans 72. Define Booleans.
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
In booleans True and False , first letters should be in ____ letter.
Capital
74
74. Example for Boolean.
1 > 2 OUT: False 1 == 1 OUT: True
75
75. ____ function is used as a place holder
None
76
a = 10 a + a OUT: 20 Reassigning: a = a + a OUT: 20 Using arithmetic operator addition: a += 10 What is the output?
OUT: 30
77
77. %s
%s operator converts whatever it sees into a string, including integers and floats.
78
78. %d
%d operator converts numbers to integers first, without rounding.
79
79. %r
%r and repr() deliver the string representation of the object, including quotation marks and any escape characters.
80
# String and List Python's built-in len( ) function counts all of the characters in the string, including ____ and ____
Spaces and Punctuation
81
# Strings Strings are a ______
Sequence
82
# Strings Indexing For indexing ______ notation is used
[ ]
83
# String , Indexing Indexing starts at ____ index
0
84
# String, Slicing ___ is used to perform slicing which can gran everything up-to a designated point
:
85
# String , Slicing How to print a string backwards using slicing ? eg: 'Hello World'
s = 'Hello World' s[ : : -1 ] OUTPUT: 'dlroW olleH'
86
# String , Slicing Grab everything past the first term all the way to the length of s s = 'Hello World'
s[ 1: ] OUTPUT: 'ello World'
87
# String, Slicing S = "Hello World" Grab everything up to the 3rd index
s[ : 3 ]
88
# String , Slicing s = 'Hello World' Grab everything
s[ : ]
89
# String , Reverse Indexing Grab everything but the last letter s = 'Hello World'
s[ : -1 ]
90
# String , Slicing s = 'Hello World' Grab everything, but go in step size of 2
[ : : -2 ]
91
# String Strings have an important property known as ____.
Immutability
92
# String What is Immutability?
Once a string is created, the elements within it can not be changed or replaced. eg. s = 'Akshita' s[0] = 'R' OUTPUT: ERROR
93
# Strings , Built in methods Give few built in methods of a String.
.upper ( ) .lower ( ) .split ( ) There are many more methods
94
# String , Print Formatting _____ method is used to add formatted objects to printed string statements.
.format( )
95
# String, Print formatting Give an example for .format( )
'Insert curly brackets { }'.format('to the string') Output: 'Insert curly brackets to the string
96
# Lists Can concatenation applied on lists
yes, Concatenation can be applied to lists merging to lists together.
97
An advanced feature of list is called _______
List Comprehension
98
_________ allow for quick construction of lists.
List Comprehension