Professional Documents
Culture Documents
Unit 2 Week 4 Part2
Unit 2 Week 4 Part2
Computer Programming
BASICS of PYTHON High-Level – program used instructions and data objects at the level of machine. Low-level languages (like C, C++)
require us to allocate and manage memory, whereas Python manages memory for us.
General Purpose - operations of the programming language are widely applicable
Practise 1: Writing your first Line of Python COMMENTS, PRINT Statement and BASIC DATA TYPES
COMMENTS, PRINT Statement and BASIC DATA TYPES COMMENTS, PRINT Statement and BASIC DATA TYPES
COMMENTS, PRINT Statement and BASIC DATA TYPES COMMENTS, PRINT Statement and BASIC DATA TYPES
important. SAMPLE CODE 2: Python will give you an error if you skip the indentation
if 5 > 2:
If A conditional statement that, if proved true, performs a
print ("Five is greater than two!")
function or displays information. SAMPLE CODE 3: The number of spaces is up to you as a programmer, but it has to
> and < Greater than and less than symbols can be used to be at least one. if 5 > 2:
compare numbers and expressions. print ("Five is greater than two!")
if 5 > 2:
print("Five is greater than two!")
26 By: JMI 27 By: JMI
COMMENTS, PRINT Statement and BASIC DATA TYPES COMMENTS, PRINT Statement and BASIC DATA TYPES
COMMENTS, PRINT Statement and BASIC DATA TYPES COMMENTS, PRINT Statement and BASIC DATA TYPES
Integers Floats
Integers or ints are positive or negative WHOLE numbers with no When a number has a decimal point on it, they’re known as
decimal point. floating point data types. It doesn’t matter if it has 1 digit, or 20,
it’s still a float.
Encode and run the cell. The resulted output should be a series of Encode and run the cell. The output should be a series of numbers
numbers 2 and 10. 10.953 and 8.0.
30 By: JMI 31 By: JMI
COMMENTS, PRINT Statement and BASIC DATA TYPES COMMENTS, PRINT Statement and BASIC DATA TYPES
Booleans STRINGS
The boolean data type is either a True or False value. Think of it
Also known as “String Literals,” these data types are the most complex among
like a switch, where it’s either off or on. the four types . The actual definition of a string is Strings in Python are arrays
Booleans are a key data type, as they provide several uses. One of of bytes representing unicode characters.
the most common is for tracking whether something occurred. Strings are nothing more than a set of characters, symbols, numbers,
whitespace, and even empty space between two or single sets of quotation
marks.
Whatever is wrapped inside of the quotation marks will be considered a string,
even if it’s a number.
Encode and run the cell. The output should be the words True and
False, respectively.
32 By: JMI 33 By: JMI
STRINGS
Encode and run the cell. The output will include an empty line at the
top, as we print out nothing in the first statement.
34 By: JMI