Python Basics I – Variables, Data Types, Conditionals.pptx
AAplayz77
11 views
17 slides
Aug 30, 2025
Slide 1 of 17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
About This Presentation
..
Size: 72.36 KB
Language: en
Added: Aug 30, 2025
Slides: 17 pages
Slide Content
Python Basics I – Variables, Data Types, Input/Output, Conditionals Title Slide
Today’s Session Declare and use of Variables Identify Data types Understand Conditionals in python Understand Input/Output in python Applying Concepts
Variables Variables are containers for storing data values. These values can be used later in the program Python doesn’t have a command to declare variables but rather a variable is created the moment you assign a value
x = 5 y = “Name Here” z = x/5 print(x) print(y) print(z) Example Here variables x, y, and z are defined values. Then the variables are printed.
Variable Naming Scheme 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.
Variable Naming Scheme Variable names with more than one word can be difficult to read. Therefore there are 3 common ways you name variables Camel Case: Each word, except the first, starts with a capital letter Pascal Case: Each word starts with a capital letter Snake Case: Each word is separated by an underscore character
Data Types Variables can store data of different types, and different types can do different things. Each data type defines the type of value. Python has the following data types Numeric – int, float, complex Sequence- list, tuple, range, str Set Mapping – dict Boolean – bool None – NoneType
Arithmetic operators are used for basic math operations + used for addition used for subtraction * used for multiplication / used for division // used for floor division [Divides numbers and remove the decimals] % used for modulus [Gives remainder from division] ** used for exponentiation Arithmetic Operators
Output / Input Outputting values in python is possible by using the print() function. It can be used to output variable values. You can output multiple variables values using commas x = 9 y = 10 print( x,y )
Python Conditionals Conditionals are used in python to make decisions in code depending on output A condition can be made which when true, a specific part of a code will be run Else is used in python when you want a result for when the condition is false The syntax is: if condition: #operation
x = int(input(“input age”)) If x >= 18: print(“You can vote”) else: print(“You cant vote”) Example
Python Conditionals You can add multiple conditions using elif . This is done when you have multiple conditions and results Syntax is: marks = 85 if marks >= 90: print("Grade A") elif marks >= 75: print("Grade B") else: print("Grade C")
Operators For conditions you need operators to compare values. Comparison operators include: == which is ‘equals to’. Returns true if value to left and right are equal != which is ‘not equals to’. Returns true if value to left and right aren’t equal > which is ‘greater than’. Returns true if value to left is greater than right < which is ‘lesser than’. Returns true if value to left is lesser than right >= which is ‘greater or equal’. Returns true if value to left is greater or equal than right <= which is ‘lesser or equal’. Returns true if value to left is lesser or equal than right
Operators You can combine multiple conditions using logical operators Logical Operators include: and which only returns true when both conditions on each side are equal or which only returns true when either condition on each side is equal not which returns true when the condition is false
Nested Conditionals You can have if statements inside if statements, this is called nested if statements. x = 41 if x > 10: print("Above ten,") if x > 20: print("and also above 20!") else: print("but not above 20.")
Exercise Create a calculator using python. User must input the values and also input the operation