After_Sumrize
After_Sumrize
After_Sumrize
Python is a programming discipline that is optionally written, can be easily understood and the
organization of a language is closely related to the business model, the way data and image (voice,
etc.) is supported, the supported platform, and the supported wireless device.
Let’s break down the basics for someone starting fresh.
1. What is Python?
Syntax is easy to learn and Python, being high level, abstracts away the east of search of machine
learning problem. It also a beginner programming language.
Interpreted:
Executes code line-by-line, making it beginner-friendly.
Dynamically
Typed: No need to declare variable types.
High-Level:
Abstracts low-level details, allowing you to focus on problem-solving.
Versatile:
Used in various fields like web development, data science, and machine
learning.
2. Installing Python
Getting started with Python can be done by downloading it from the official website.
Download
Python from the official
website.
Install
Python, ensuring the option "Add Python to PATH" is
checked during installation.
Verify
installation by typing python --version in the terminal or command prompt.
You have been given the serial number on the PC at which you copied the file
Python
Shell: Interactive console for running Python commands.
Script
File: Save your code in a .py file and run it using python filename.py.
Hello, World! Example
print("Hello, World!")
Run the code and you will see "Hello, World!" printed on your screen.
Copy code
Hello, World!
4. Python Basics
Variables are units that can store data. Declaring the type is unnecessary.
# Variables
name = "Alice" # String
age = 25 #
Integer
height = 5.7 #
Float
is_student = True #
Boolean
print(name, age, height, is_student)
4.2 Input and Output
Input:
Let the end-user to input data.
Output:
Show data to the end-user.
If-Else
Statement
# For loop
for i in range(5):
print(i
fruits.append("orange")
print(fruits)
Tuples:
Ordered, immutable collections.
unique_numbers = {1, 2, 3, 2}
print(unique_numbers)
# Output: {1, 2, 3}
6. Working with Libraries
Python is a software language that touches all the trees in the park. This is how we talk about python.
It’s the
Learn Variables in Python
What is a Variable?
Python coding language needs a variable in order to hold and operate data
Using variables is the best way to store, manipulate, and
restore the data in the computing universe. To sum up, the significance of
they can hardly be overstated.
Put it simply, a variable is a container where we can save
data in the memory space. This idea can be explained by creating a reference
(like a name) to a value with changing content, which is a variable. Variables
enable us to store data in the memory,
alter it and then make use of this data in the program
many times
In case you would like to analyze many different examples or
should you have any questions on variables, the information shared with you and
the examples given will help you understand the subject
and make it easier to answer.
Basic Syntax
Naming:
The names of variables can consist of any letters, numbers,
and underscores in the names, but they should not start with a number. Porting
data of the same type (like age and Age) to the same place results in
variable naming difference.
Arranging the Variables by the Data
Type: Variables can be used to keep different kinds of data in them:
Integers
(int): Whole numbers (e.g., 42)
Floats
(float): Decimal numbers (e.g., 3.14)
Text
(str): Text is a string of characters (e.g., "Hello")Boolean
(bool): A boolean is a data type that can have either of two values: True or False. Examples 1: The
basic usage of the variableSuppose you are storing information about a person:name = "John Doe"age
= 28height = 5.9 # in
feetis_student = TrueThus, in this case, you are saving name, age, height, and is_student as
variables.Example 2: Cost estimation with variablesIn case you need to keep track of all your expenses
for a week, write:monday_expense = 20.50tuesday_expense = 15.75wednesday_expense =
30.00total_expense = monday_expense + tuesday_expense +
wednesday_expense.print("Total weekly expense:", total_expense)You can learn from this example how
variables assist you during calculations and data analysis.Example 3: Inventory ManagementSuppose
this is an everday an inventory system for a store:item_name = "Apples"item_price =
1.50item_quantity = 100total_value = item_price * item_quantityprint(f"Total value of {item_name}:
${total_value}")Reassigning VariablesAt any moment, you are allowed to update the value of a
variable:age = 30print(age) # Output:
30age = 31print(age) # Output:
31Variable ScopeVariables fall within the scope of a certain function, meaning that they are only
accessible within the function. Two most common typesGlobal
Variables: The variables that are not in a function. Variables that can be
accessed from the entire program.Example of Scopedef my_function():local_var = 10 #
Local variable print(local_var)my_function()# print(local_var) #
This would raise an error because local_var is not accessible here.global_var = 20 #
Global variabledef another_function():
print(global_var) # This can
access global_varanother
Text
(str): Text is a string of characters (e.g., "Hello")
Boolean
(bool): A boolean is a data type that can have either of two values: True or False.
Global
Variables: The variables that are not in a function. Variables that can be
accessed from the entire program.