KEMBAR78
Introduction to Python Programming Basics | PDF
Python Basics
North Eastern Mindanao State University
College of Information Technology Education
Department of Computer Studies
JHON MARK C. PALEN
Prepared by:
Python Basics Outline
Python syntax and indentation
Variables and Data types
Input and Output in Python
Python Syntax
print(“Hello Word”)
Write a script that
will Print,
Hello World!
Exercise 1
Write a script that will Print,
FullName: John Rey Ramirez
Email: jrramirez@nemsu.edu.ph
Age: 20
Exercise 2
What is Variables?
What is Variables?
The variable is a named storage
location that holds a value or data.
These values can change during the
execution of a program, hence the
term "variable." Variables are essential
for storing and manipulating data in
computer programs.
Variable Names
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume). Rules for
Python variables:
A variable name must start with a letter or the underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive (age, Age and AGE are three different variables)
A variable name cannot be any of the Python keywords.
What is
Data types?
What is Data types?
Data types are classifications that
specify the type of data a variable
can hold. Python provides several
built-in data types to handle
different kinds of data.
Basic Data Types
String
int
boolean
float
(Sentences, Phrases, Character): identifier = “Hello World”
(Positive & Negative Numbers): identifier = 5
(float (Decimal Numbers): identifier = 24.3424
(True or False): identifier = true
Identifiers?
Identifiers
The name of the variable which the
user decides to choose.
Syntax:
firstName = “John”
lastName = “Doe”
(identifier = value)
Types of Comments in Python
Single-Line Comments (#)
A single-line comment starts with the # symbol. Anything after # on
the same line is ignored by Python.
Multi-Line Comments (Using """ """ or ''' ''')
Python does not have a built-in multi-line comment syntax like some
other languages, but you can use triple quotes (""" """ or ''' ''') as a
workaround.
print()
Used to display something in
the console
Syntax:
Print(variable)
Working with
String
What is String?
What is String?
String is a sequence of character
String may contain alphabets, numbers and special
characters.
Usually string are enclosed within a single quotes and
double quotes.
String is immutable in nature
a = ‘Hello World!’ b = “Python”
Inbuilt String Functions
Python mainly contains 3 inbuilt string functions.
len()
min()
max()
Find out the lenght of characters in string.
Smallest value in a string based on ASCII values
Largest value in a string based in ASCII values
print(len("Python Programming"))
print(min("Python Programming"))
print(max("Python Programming"))
Write a script that will use
variables and Print the result,
FullName: John Rey Ramirez
Length: 16
Exercise 3
Arithmetic Operators
Used to perform mathematical operations inside our
programming language.
a = “2”
b = “2”
print(a+b)
Exercise 4
Exercise 5
a = “2”
b = 2
print(a+b)
OPERATORS SYNTAX RESULT
Subtraction x - y Difference
Addition x + y Sum
Multiplication x * y Product
Division x / y Quotient
Modulus x % y Remainder
Exponent x ** y Power
Arithmetic Operators
input()
Used to make the user input
something in the console.
Syntax:
identifier= input()
identifier= input(“Enter Firstname: ”)
Casting Variables
A Technique used to convert a datatype to another datatype
Syntax:
Convert Numbers to String
Convert String to Numbers
str(number)
int(string)
float(string)
Make a One Function Calculator
Try to create a program that will perform one of the
arithmetic operators when the user inputs 2 numbers
Sample Output:
Enter first Number: 20
Enter Second Number: 40
The result of 20 + 40 = 60
For your attention and participation
Thank You!
JHON MARK C. PALEN
Instructor I

Introduction to Python Programming Basics

  • 1.
    Python Basics North EasternMindanao State University College of Information Technology Education Department of Computer Studies JHON MARK C. PALEN Prepared by:
  • 2.
    Python Basics Outline Pythonsyntax and indentation Variables and Data types Input and Output in Python
  • 3.
  • 4.
    Write a scriptthat will Print, Hello World! Exercise 1
  • 5.
    Write a scriptthat will Print, FullName: John Rey Ramirez Email: jrramirez@nemsu.edu.ph Age: 20 Exercise 2
  • 7.
  • 8.
    What is Variables? Thevariable is a named storage location that holds a value or data. These values can change during the execution of a program, hence the term "variable." Variables are essential for storing and manipulating data in computer programs.
  • 9.
    Variable Names A variablecan have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables: A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables) A variable name cannot be any of the Python keywords.
  • 10.
  • 11.
    What is Datatypes? Data types are classifications that specify the type of data a variable can hold. Python provides several built-in data types to handle different kinds of data.
  • 12.
    Basic Data Types String int boolean float (Sentences,Phrases, Character): identifier = “Hello World” (Positive & Negative Numbers): identifier = 5 (float (Decimal Numbers): identifier = 24.3424 (True or False): identifier = true
  • 13.
  • 14.
    Identifiers The name ofthe variable which the user decides to choose. Syntax: firstName = “John” lastName = “Doe” (identifier = value)
  • 15.
    Types of Commentsin Python Single-Line Comments (#) A single-line comment starts with the # symbol. Anything after # on the same line is ignored by Python. Multi-Line Comments (Using """ """ or ''' ''') Python does not have a built-in multi-line comment syntax like some other languages, but you can use triple quotes (""" """ or ''' ''') as a workaround.
  • 16.
    print() Used to displaysomething in the console Syntax: Print(variable)
  • 17.
  • 18.
  • 19.
    What is String? Stringis a sequence of character String may contain alphabets, numbers and special characters. Usually string are enclosed within a single quotes and double quotes. String is immutable in nature a = ‘Hello World!’ b = “Python”
  • 20.
    Inbuilt String Functions Pythonmainly contains 3 inbuilt string functions. len() min() max() Find out the lenght of characters in string. Smallest value in a string based on ASCII values Largest value in a string based in ASCII values print(len("Python Programming")) print(min("Python Programming")) print(max("Python Programming"))
  • 21.
    Write a scriptthat will use variables and Print the result, FullName: John Rey Ramirez Length: 16 Exercise 3
  • 22.
    Arithmetic Operators Used toperform mathematical operations inside our programming language.
  • 23.
    a = “2” b= “2” print(a+b) Exercise 4
  • 24.
    Exercise 5 a =“2” b = 2 print(a+b)
  • 25.
    OPERATORS SYNTAX RESULT Subtractionx - y Difference Addition x + y Sum Multiplication x * y Product Division x / y Quotient Modulus x % y Remainder Exponent x ** y Power Arithmetic Operators
  • 26.
    input() Used to makethe user input something in the console. Syntax: identifier= input() identifier= input(“Enter Firstname: ”)
  • 27.
    Casting Variables A Techniqueused to convert a datatype to another datatype Syntax: Convert Numbers to String Convert String to Numbers str(number) int(string) float(string)
  • 28.
    Make a OneFunction Calculator Try to create a program that will perform one of the arithmetic operators when the user inputs 2 numbers Sample Output: Enter first Number: 20 Enter Second Number: 40 The result of 20 + 40 = 60
  • 29.
    For your attentionand participation Thank You! JHON MARK C. PALEN Instructor I