Introduction Flashcards
Data Types
- How many data types are there in python
There are 8 data types, they are:
- Integer - int
- Floating Point - float
- String - str
- Lists - list
- Dictionary - dict
- Tuples - tup
- Sets - set
- Booleans - bool
Data Types
- Integer
Whole Numbers, positive or negative
Example:
- 2 444 66
Data Types
- Floating Point
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)
Data Types
- String
Ordered sequence of Characters- ‘‘hello’’ ‘999’ “34ndj”
Data Types
- Lists
Ordered sequence of Objects - [“apple”, 10, 1.24]
Data Types
- Dictionaries
Unordered Key, value pairs - {“mykey”: “value”, “name”: “franky”}
Data Types
- Tuples
Ordered immutable sequence of objects -
( 10, “hello”, 200.3)
Data Types
- Sets
Unordered collection of unique objects - {“a”, “b”}
Data Types
- Booleans
Logical Value indicating - True or False
Data Types
- What do you mean by data types?
Data type is a classification that specifies which type of value a variable has.
Data type
- What is a variable in python?
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
Data type
Numbers
- What are the Arithmetic Operators?
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 %
Data type
- ________ Brings back reminder after division
Modulo or Mod operator
Data type
- 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?
Modulo or Mod
Data type
- What is the difference between floating point and an integer?
Integer - Whole Number
Floating point - Decimal Number
Variable Assignments
Variable Assignments
- What are the rules followed in naming variables?
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
Data type
- Python uses _____ typing
Dynamic
Data type
- What is Dynamic Typing? and What are the pros and cons of dynamic typing?
Dynamic typing enables to reassign variables to different data types.
- Pros of Dynamic Typing
- very easy to work with
- faster development time
- Cons of Dynamic Typing
- may result in unexpected bugs!
- you need to be aware of type()
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?
i. = , name = object
ii. type( variable name )
String
- What is a String?
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”
String
- What are the features Indexing ?
- 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
String
- What is Slicing?
Slicing - Grabs a subsection of multiple characters
i.e. A “Slice of a string”
- [Start:Stop:Step]
- Define Start , Stop , Step?
Start - Numerical index for the slice Start
Stop - The index u will go uptown but not include
Step - Size of the ‘Jump’ u take
String
- How to apply Print Function?
The commons has taken out the double quotes and given the output
print (“Hello World”)
Hello World
String
- What if “Hello World” is typed in directly without using print( )?
IN : “Hello World”
OUT : “Hello World”
output comes as it was typed in
Strings
- ESCAPE SEQUENCE
\n
String
- How to run the Escape Sequence?
IN : print ( ‘Hello\nWorld’ )
OUT : Hello
World
String
- How to run TAB command ?
gives 4 spaces between the words
- \t
IN : print (‘Hello\tworld”)
Out: Hello World
String
- LENGTH FUNCTION
- len
- outputs length of the string
- len( ‘hello’ )
- OUT: 5
String
- In length function ______ is counted as a character.
Space
String
String Indexing and Slicing
- ________ grabs single characters from a string.
String Indexing
String
- name. = “Sam”
name[0] = ‘P’
Can’t do this for a string because strings are _______.
Immutable
String
- Merging two strings together are called __________.
Concatenation
String
- Give an example for concatenation.
last_letters = ‘am’
‘P’ + last_letters
OUT : ‘Pam’
String
- How to run multiple concatenation?
letter = ‘A’
letter * 10
OUT : ‘ AAAAAAAAAA’
String
- To get Methods and attributes on Jupiter notebook, _______ is to be clicked.
Tab
String
- Are strings mutable?
Strings are not mutable (meaning it cannot use indexing to change individual elements of a string)
String
- How to create comments in of a code?
Using #HASTAG
String
Print Formatting and Strings
- 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’)