0% found this document useful (0 votes)
3 views16 pages

Module 4

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
3 views16 pages

Module 4

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 16

Engineering-Computing Academy of

Science and Technology


BSIT

Course Code CCC 112 A


Course Description Introduction to Computer Programming 1
Module Title Basics of Python

I. INTRODUCTION:

Understanding Python's syntax and data types is fundamental to harnessing the power of
this versatile programming language. Python's syntax emphasizes readability and
simplicity, enabling developers to write clean, concise code with ease. Its dynamic typing
system supports a variety of data types, including integers, strings, and complex
structures, allowing seamless handling of diverse data. These features are complemented
by Python’s indentation rules, which structure code blocks for better readability and
functionality. Together, these elements form the foundation of Python programming,
empowering developers to create efficient, scalable, and innovative solutions across a
wide range of applications.

II. PRE- DISCUSSION ACTIVITY:


Engineering-Computing Academy of
Science and Technology
BSIT

III.DISCUSSION:
CHAPTER 4.1 Introduction to Python

What is Python?

Python is a set of instructions that we give in the form of a Program to our

computer to perform any specific task. It is a Programming language having

properties like it is interpreted, object-oriented and it is high-level too. Due to its

beginner-friendly syntax, it became a clear choice for beginners to start their

programming journey. The major focus behind creating it is making it easier for

developers to read and understand, also reducing the lines of code.

History of Python

Python was created in 1980s by Guido van Rossum. During his research at the

National Research Institute for Mathematics and Computer Science in the

Netherlands, he created Python – a super easy programming language in terms

of reading and usage. The first ever version was released in the year 1991 which

had only a few built-in data types and basic functionality.

Later, when it gained popularity among scientists for numerical computations

and data analysis, in 1994, Python 1.0 was released with extra features like
Engineering-Computing Academy of
Science and Technology
BSIT

map, lambda, and filter functions. After that adding new functionalities and

releasing newer versions of Python came into fashion.

What can Python do?

 Python can be used on a server to create web applications.

 Python can be used alongside software to create workflows.

 Python can connect to database systems. It can also read and modify files.

 Python can be used to handle big data and perform complex mathematics.

 Python can be used for rapid prototyping, or for production-ready software

development.

Why Python?

 Python works on different platforms (Windows, Mac, Linux, Raspberry Pi,

etc).

 Python has a simple syntax similar to the English language.

 Python has syntax that allows developers to write programs with fewer

lines than some other programming languages.

 Python runs on an interpreter system, meaning that code can be executed

as soon as it is written. This means that prototyping can be very quick.


Engineering-Computing Academy of
Science and Technology
BSIT

 Python can be treated in a procedural way, an object-oriented way or a

functional way.

CHAPTER 4.2 Python Basic Syntax

Python syntax is like grammar for this programming language. Syntax refers to

the set of rules that defines how to write and organize code so that the Python

interpreter can understand and run it correctly. These rules ensure that your

code is structured, formatted, and error-free.

Indentation in Python

Python Indentation refers to the use of whitespace (spaces or tabs) at the

beginning of code line. It is used to define the code blocks. Indentation is crucial

in Python because, unlike many other programming languages that use braces

"{}" to define blocks,

Python uses indentation. It

improves the readability of

Python code, but on other

hand it became difficult to rectify indentation errors. Even one extra or less space

can lead to indentation error.


Engineering-Computing Academy of
Science and Technology
BSIT

Python Variables

Variables in Python are essentially named references pointing to objects in

memory. Unlike some other languages, you don't need to declare a variable's

type explicitly in Python. Based on the value assigned, Python will dynamically

determine the type.

In the below example, variable 'a' is initialize with integer value and variable 'b'

with a string. Because of dynamic-types behavior, data type will be decide

during runtime.

Python Identifiers

In Python, identifiers are unique names that are assigned to variables,

functions, classes, and other entities. They are used to uniquely identify the
Engineering-Computing Academy of
Science and Technology
BSIT

entity within the program. They should start with a letter (a-z, A-Z) or an

underscore "_" and can be followed by letters, numbers, or underscores.

Output Variables

The Python print() function is often used to output

variables.

In the print() function, you output multiple variables,

separated by a comma:

You can also use the + operator to output multiple variables:


Engineering-Computing Academy of
Science and Technology
BSIT

Global Variables

Variables that are created outside of a

function are known as global

variables. Global variables can be

used by everyone, both inside of functions and outside.

Taking Input from User in

Python

The input() function in

Python is used to take user

input from the console. The

program execution halts until

the user provides input and presses "Enter". The entered data is then returned

as a string. We can also provide an optional prompt as an argument to guide

the user on what to input.


Engineering-Computing Academy of
Science and Technology
BSIT

CHAPTER 4.3 Python Data Types

Built-in Data Types

In programming, data type is an important concept. Variables can store data of

different types, and different types can do different things. Python has the

following data types built-in by default, in these categories:

Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Mapping Type: dict

Set Types: set, frozenset

Boolean Type: bool

Binary Types: bytes, bytearray, memoryview

None Type: NoneType


Engineering-Computing Academy of
Science and Technology
BSIT

Python Numbers

There are three numeric types in

Python:

 int

 float

 complex

Variables of numeric types are created when you assign a value to them:

Python Casting

Specify a Variable Type

There may be times when you want to specify a type on to a variable. This can

be done with casting. Python is an object-orientated language, and as such it

uses classes to define data types, including its primitive types.

Casting in python is therefore done using constructor functions:


Engineering-Computing Academy of
Science and Technology
BSIT

 int() - constructs an integer number from an integer literal, a float literal (by

removing all decimals), or a string literal (providing the string represents a

whole number)

 float() - constructs a float number from an integer literal, a float literal or a

string literal (providing the string represents a float or an integer)

 str() - constructs a string from a wide variety of data types, including

strings, integer literals and float literals

CHAPTER 4.4 Python Strings


Engineering-Computing Academy of
Science and Technology
BSIT

Strings

Strings in python are surrounded by either single quotation marks, or double

quotation marks.

'hello' is the same as "hello".

You can display a string literal with the print() function:

Assign String to a Variable

Assigning a string to a variable is done with the variable name followed by an

equal sign and the string:


Engineering-Computing Academy of
Science and Technology
BSIT

String Slicing in Python

String slicing in Python is a way to get specific parts of a string by using start,

end, and step values. It’s especially useful for text manipulation and data

parsing.

Python - Modify Strings

Upper Case

The upper() method returns the string in upper case:

a = "Hello, World!"

print(a.upper())
Engineering-Computing Academy of
Science and Technology
BSIT

Lower Case

The lower() method returns the string in lower case:

a = "Hello, World!"

print(a.lower())

Replace String

The replace() method replaces a string with another string:

a = "Hello, World!"

print(a.replace("H", "J"))

String Concatenation

To concatenate, or combine, two strings

you can use the + operator.


Engineering-Computing Academy of
Science and Technology
BSIT

We cannot combine strings and numbers like this:

But we can combine strings and numbers by using f-strings or

the format() method!

F-Strings

F-String was introduced in Python 3.6, and is now the preferred way of

formatting strings.
Engineering-Computing Academy of
Science and Technology
BSIT

To specify a string as an f-string, simply put an f in front of the string literal, and

add curly brackets {} as placeholders for variables and other operations.

III. ASSESSMENT:

Reference List:
C - Basic Syntax. (n.d.). https://www.tutorialspoint.com/cprogramming/c_basic_syntax.htm

GeeksforGeeks. (2023, June 16). C Basic Syntax. GeeksforGeeks. https://www.geeksforgeeks.org/c-

basic-syntax/

S, H. S. (2024, July 23). The One-Stop Solution To Learn Everything You Need To Know About

Variables In C. Simplilearn.com. https://www.simplilearn.com/tutorials/c-tutorial/what-is-

variables-in-c#:~:text=In%20C%20programming%20language%2C%20a,times%20during

%20the%20program%20execution.
Engineering-Computing Academy of
Science and Technology
BSIT

W3Schools.com. (n.d.). https://www.w3schools.com/c/c_variables_reallife.php

What is an IDE? - Integrated Development Environment Explained - AWS. (n.d.). Amazon Web

Services, Inc. https://aws.amazon.com/what-is/ide/

Prepared by: Reviewed by: Recommending Approved:


Approval:

Justin Nichol P. Dr. Jane M. Virgo C. Lopez, PhD Donna Padilla


Pasamonte Fernandez Vice President for Taguiba, PhD
Faculty,E-Coast Dean,E-Coast Academics President

You might also like