Docsity

Python Programming Module 1, Lecture notes of Programming Languages

Toggle sidebar
bg1
Python Basics
Course Code
PYCS01
MODULE 1
OVERVIEW
1. What is Python?
2. Why use Python?
3. Data Types
4. String
5. Arithmetic Operators
6. Variables
7. Comments
8. print() function
9. input() function
10. Casting
What is Python?
● Python is an interpreted, object-oriented,
high-level programming language.
● Its creator is Guido van Rossum, and it was
released in 1991.
WHY USE PYTHON?
● Easy to learn and use
○ Easy-to-read syntax
○ Intuitive
○ Easy to understand for beginners
● Versatile
○ Can be used for web development, data
analysis, artificial intelligence, scientific
computing, game development, and
more.
● Large community and ecosystem:
○ Python has a large and active
community of developers who
contribute to the development of
libraries and tools.
● Cross-platform support:
○ Can run on multiple operating systems:
Windows, macOS, Linux
● High-level Language:
○ Designed to be human-readable, making
it easier to write and maintain code.
● Interpreted language
○ In Python, there is no need to compile
code before it can be executed.
○ So it means that it is faster and easier to
write and test our code.
DATA TYPES
Data Type
Description
Example
str
String, text
Uses either single or
double quotes.
“Hello World”
‘I am 100 years
old’
int
Integers, whole
numbers
10
float
Floating point
numbers, decimal
numbers
10.5
bool
Boolean, true or false
True
list
Ordered, changeable
collection of values.
Uses square brackets
[]
[1,2,3]
tuple
Ordered,
(1,2,3)
1
pf3
pf4

Partial preview of the text

Download Python Programming Module 1 and more Lecture notes Programming Languages in PDF only on Docsity!

Python Basics

Course Code PYCS

MODULE 1

OVERVIEW

  1. What is Python?
  2. Why use Python?
  3. Data Types
  4. String
  5. Arithmetic Operators
  6. Variables
  7. Comments
  8. print() function
  9. input() function
  10. Casting

1 What^ is^ Python?

● Python is an interpreted, object-oriented, high-level programming language. ● Its creator is Guido van Rossum, and it was released in 1991. 1.1 WHY USE PYTHON? ● Easy to learn and use ○ Easy-to-read syntax ○ Intuitive ○ Easy to understand for beginners ● Versatile ○ Can be used for web development, data analysis, artificial intelligence, scientific computing, game development, and more. ● Large community and ecosystem: ○ Python has a large and active community of developers who contribute to the development of libraries and tools. ● Cross-platform support: ○ Can run on multiple operating systems: Windows, macOS, Linux ● High-level Language: ○ Designed to be human-readable, making it easier to write and maintain code. ● Interpreted language ○ In Python, there is no need to compile code before it can be executed. ○ So it means that it is faster and easier to write and test our code. 1.2 DATA TYPES Data Type Description Example str String, text Uses either single or double quotes. “Hello World” ‘I am 100 years old’ int Integers, whole numbers

float Floating point numbers, decimal numbers

bool Boolean, true or false True list Ordered, changeable collection of values. Uses square brackets []

[1,2,3]

tuple Ordered, (1,2,3)

unchangeable collection. Uses parentheses () set Unordered collection of unique values. Uses curly braces {}

dict Dictionary, stores key-value pairs {“name”: “Juan”} None Represents no value None 1.3 STRING ● String - series of characters interpreted as text. ● You can use either single or double quotes to define a string. name = 'John' name = "John" String Concatenation first = "John" last = "Doe" full_name = first + " " + last print(full_name) Output: John Doe f-strings One of the easiest ways to insert variables into strings: name = "John" age = 20 print(f"My name is {name} and I am {age} years old.") Output: My name is John and I am 20 years old. Multiple Line of Text Use 3 double quotes or 3 single quotes text = “””This is an example of multiple text in Python.””” print(text) Output: This is an example of multiple text in Python. String Formatting Functions upper() Converts into upper case lower() Converts into lower case capitalize() Converts the first character to uppercase title() Converts the first character of each word to uppercase split() Splits the string at the specified separator, and returns a list replace() Returns a string where a specified value is replaced with a specified value len() Count characters in a string 1.4 ARITHMETIC OPERATORS Operator Description

  • Addition - adds values
  • Subtraction - subtracts values
  • Multiplication - multiplies values / Division - divides the left-hand operand by the right-hand operand % Modulus - Divides the values and returns the remainder ** Exponent - Performs exponential calculations

1.9 CASTING

Converting one data type into another is called type casting. Common Conversions: ● int() ● float() ● str() ● bool() Example: number = "25" print(int(number) + 5) Output: 30