0% found this document useful (0 votes)
18 views14 pages

Day 1 Session

Uploaded by

misaeldrumss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views14 pages

Day 1 Session

Uploaded by

misaeldrumss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Universidad Autónoma de San Luis Potosí

z
Python Basics
z
What is and Why Python?

It is used for:
• web development (server-side)
• software development
• mathematics
• system scripting

• 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 can be treated in a procedural way, an object-oriented way or a
functional way.
z
Getting Started with Python

- Check Python Version with: python --version


- Python CLI
- Creation of files with CLI
- Hello World!
z
Python Comments

Comments can be used to explain Python code.


Comments can be used to make the code more readable.
Comments can be used to prevent execution when testing code.
Multiline comments.

Comments starts with a #, and Python will ignore them.


# This is a comment
z
Python Variables
- Variables are containers for storing data values.

- Python has no command for declaring a variable.


A variable is created the moment you first assign a value to it.

- Variables do not need to be declared with any particular type, and


can even change type after they have been set.

- You can get the data type of a variable with the type() function.
z
Python Variables
A variable can have a short name (like x and y) or a more descriptive
name (age, carname, total_volume). Rules for Python variables:

1. A variable name must start with a letter or the underscore character


2. A variable name cannot start with a number
3. A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
4. Variable names are case-sensitive (age, Age and AGE are three
different variables)
5. A variable name cannot be any of the Python keywords.

Multi words variable names: myCamelCase, MyPascalCase,


my_snake_case
z
Python Basic Data Types
# String
greeting = 'Hello, friend’ # “Hello, friend”

# Integer
age = 35

# Floats
speed1 = 4.5
speed2 = 4.0
speed3 = 4.

# Boolean
am_i_short = True
am_i_tall = False

You can get the data type of any object by using the type() function
z
Assign multiple values
Python allows you to assign values to multiple variables in one line:

x, y, z = "Orange", "Banana", "Cherry"


print(x)
print(y)
print(z)

And you can assign the same value to multiple variables in one line:

x = y = z = "Orange"
print(x)
print(y)
print(z)
z
Arithmetic Operators
z
Assignment Operators
z
Comparison Operators
z
Logical Operators

Logical operators are used to combine conditional statements:


z
print()
z
Input()

Python allows for user input. That means we are able to ask the user for input.
#The input() always return a STRING Value even when the
user inputs numbers

username = input("Enter username:")


print("Username is: " + username)

You might also like