Lecture 2 Data_Types - Part A
Lecture 2 Data_Types - Part A
Programming Principles
Lecture 2: Data Types and Selection
This Lecture
• Data types
– Common data types: integer, float, string and boolean
– Weak/Strong typing and type conversion
– Implicit and explicit conversion
– Static and dynamic typing
– Numeric, string and boolean conversions
Textbook
System.out.println(result); print(result)
0.0 0.75
System.out.println(result);
0.75
• True and False are the only two boolean values, but values
of other data types can be converted to boolean values
– The bool() function converts a value to a boolean value
bool(5) # positive number Python bool(0) # int of 0 Python
True False
bool(-245.271) # negative number bool(0.0) # float of 0.0
True False
bool('False') # string of False bool('') # empty string
True False
bool('0') # string of 0 bool([]) # an empty "list"
True False
– End of Part A