Data Type
Data Type
Soohyun Yang
College of Engineering
Department of Civil and Environmental Engineering
Data type 1 - Numbers
Three types of numbers exist.
1) Integer : A whole number without a fractional part.
e.g.) 0, -153, 2*10**3
2) Float : Real numbers with a decimal point.
>Note 1: The scientific notation ‘e’ (i.e., the power of 10) yields always float-type.
e.g.) 97.4, -3.5e-1, 2e+3
3) Complex : A number with real and imaginary components.
>Note 2: The character ‘j’ is only valid for an imaginary component.
>Note 3: A number must be multiplied with the character ‘j’.
e.g.) 3+1j, -4.5-2j, 9+0.5j
Data type – Numbers (con’t)
A number’s type can be checked A number’s type, except complex,
via the type() function. can be converted to another.
• int(float)
• float(integer)
• complex(integer or float)
Data type 2 - String
A string : A collection of characters that are set between
apostrophes (‘ ’), quotation marks (“ ”), or triple apostrophes or
quotation marks.
• Same results from the different four options!
• Hence, you can use one of the four options.
• .... BUT, you should be careful if your string
includes apostrophe or quotation mark.
• e.g.: how to make a string variable Dog’s cute ?
Data type – String (con’t)
Operations
1) Concatenation : The plus symbol (+) is used to combine strings.
>Note : The str() function converts a type from number to string.
Otherwise…
Elements 13 4 2
Non-negative
Index
0 1 2
Negative
Index
-3 -2 -1
Data type – List (con’t)
Concatenation (+) and repetition (*) work.
Elements 1 3 5 7 Immutable
Non-negative
Index
0 1 2 3 in a direct
Negative
way!
Index
-4 -3 -2 -1
Data type – Tuple (con’t)
Operations for the tuple are mostly similar with those for a list.
• Concatenation (+) and repetition (*) work.
• 2) Convert the tuple to a list change the list convert the list back into a tuple.
.list() function .tuple() function
Data type 5 - Dictionary
A dictionary : An unordered collection of key:value pair elements.
=> Not stored as typed-order.
Thus, no numeric index exists.
>Note: Useful format to store lots of info (e.g., model parameters, plot setting)
• “Key:Value” indicates “Label:Contents”.
• Braces “{ }” start and end a dictionary.
• Comma “ , “ differentiate elements in a dictionary.
Key Value
name Minu Gu
id 170390
year 2
Keys and values can be converted into a list or a tuple. => Easy to manage.
• .list()
• .tuple()
>Note: Operator precedence order “ Arithmetic operators > not > and > or ”
Data type – Boolean (con’t)
Boolean algebra operators (con’t)
True or False
not True
Where does ‘Boolean variable’ come from?
George Boole (1815, England – 1864, Ireland)
• Mathematician, Philosopher, and Logician
• The author of The Laws of Thought (1854),
which extended Aristotle’s logic and
attempted to give it a mathematical foundation.
=> named ‘Boolean Algebra’.
• A fundamental contributor to
the development of digital electronics
and all modern computer languages.
https://en.wikipedia.org/wiki/George_Boole
https://simplycoding.in/boolean-algebra/
https://www.maa.org/press/periodicals/mathematical-treasure-boole-s-laws-of-thought
Take-home points (THPs)
-
-
-
…