You are on page 1of 5

Week 4 Unit 2 (Basic of Python)

Computer Programming

 Python is an interpreted, high-level, general-purpose programming


language created by Guido van Rossum and first released in 1991.
Interpreted – sequence of instructions “source code” written by the programmer is executed directly by an
interpreter. Most applications designed with Python are run through the interpreter, so errors are found at
runtime.

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

 Python language constructs and object-oriented approach aim to help


programmers write clear, logical code for small and large-scale projects.
 Python It supports multiple programming paradigms,
 including structured (particularly, procedural), object-oriented, and
functional programming.
18 19 By: JMI

Computer Programming USING PYTHON SHELL

5 Reasons to choose Python as 1st Language  Python is a language that requires


1. Python is fun : Python is a relatively efficient language, requiring fewer lines of what is called an “interpreter” to read
code to produce results. and run the code we create.
2. Python is easy to set up : Some languages, such as Java or C#, have much  When Python shell is activated, it acts
higher setup and maintenance overhead. as a local interpreter within the
terminal session that is open. We can
3. Python is not going away anytime soon: In fact, Python has become the most write any Python Code that we wish to
frequently used teaching language at major universities. execute.
4. Python is a tool of choice for doing some very big things. For instance:  Python Shell is generally great for
YouTube, Google, Instagram, Pinterest, Quora, Reddit, Dropbox, Civilization IV, practicing small snippets of code, so
and more. It’s also widely used for penetration testing, data analysis, scientific that you don’t have to open an IDE and
computing, and more. run an entire file.

5. Python jobs pay well, and python programmers


20
are in high demand By: JMI 21 By: JMI

ECE 106 - Computer Programming


Prepared by: Engr. Jeanne M. Imbuido 1
Week 4 Unit 2 (Basic of Python)

Practise 1: Writing your first Line of Python COMMENTS, PRINT Statement and BASIC DATA TYPES

Using Python SHELL: What are Comments?


 Comments are like notes that you leave behind, either for yourself or someone
else to read.
 They are not read in by the interpreter, you can write whatever you want, and
the computer will ignore it.
 Good comment will be short, easy to read, and straight to the point.
 In Python, we can write comments using the hash (#) symbol for single line
comment.
 To write multiline comments so that you may write more descriptive
paragraphs for larger portions of code, we would need to use three opening
and closing double quotes (””” ”””)
22 By: JMI 23 By: JMI

COMMENTS, PRINT Statement and BASIC DATA TYPES COMMENTS, PRINT Statement and BASIC DATA TYPES

Sample Comments The PRINT Statement

 The ability to output information to the user that we can apply to


Python is what we refer to us the Print Statement
 we call it as a function in Python
 The way it works is by writing the keyword “print” followed by
parenthesis ( ).
 Whatever is inside of the parenthesis will be output for the user to
see.

24 By: JMI 25 By: JMI

ECE 106 - Computer Programming


Prepared by: Engr. Jeanne M. Imbuido 2
Week 4 Unit 2 (Basic of Python)

COMMENTS, PRINT Statement and BASIC DATA TYPES COMMENTS, PRINT Statement and BASIC DATA TYPES

Python INDENTATION Python INDENTATION


 Python uses indentation to indicate a block of code.
 Indentation refers to the spaces at the beginning of a code line. SAMPLE CODE 1:
Where in other programming languages the indentation in code is if 5 > 2:
for readability only, the indentation in Python is very print ("Five is greater than two!")

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

Python INDENTATION What are Data Types?


 Data types are how we define values, likes words or numbers.
SAMPLE CODE 4: You have to use the same number of spaces in the same block of  Data types define what we can do and how these values are
code, otherwise Python will give you an error stored in memory on the computer.
if 5 > 2:
print ("Five is greater than two!")
print ("Five is greater than two!")

28 By: JMI 29 By: JMI

ECE 106 - Computer Programming


Prepared by: Engr. Jeanne M. Imbuido 3
Week 4 Unit 2 (Basic of Python)

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

ECE 106 - Computer Programming


Prepared by: Engr. Jeanne M. Imbuido 4
Week 4 Unit 2 (Basic of Python)

COMMENTS, PRINT Statement and BASIC DATA TYPES

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

ECE 106 - Computer Programming


Prepared by: Engr. Jeanne M. Imbuido 5

You might also like