Python Basics I – Variables, Data Types, Conditionals.pptx

AAplayz77 11 views 17 slides Aug 30, 2025
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

..


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

#CamelCase myCamelCase = “Name” #PascalCase MyPascalCase = “Age” #SnakeCase my_snake_case = “ID” Example

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
Tags