0% found this document useful (0 votes)
13 views

Variables

Uploaded by

hanyeelovesgod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Variables

Uploaded by

hanyeelovesgod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

035.

001 Spring, 2024

Digital Computer Concept and Practice


Variables

Soohyun Yang

College of Engineering
Department of Civil and Environmental Engineering
Python - Introduction
 What?
- A widely-used, general-purpose, high-level programming language
 By whom? When?
- Guido van Rossum (A Dutch programmer), Implementation started in 1989
 Development background?
- He had been looking for a 'hobby' programming project
that would keep him occupied during the week around Christmas.
 Origin of the name ‘Python’? (Large snake?)
- He was a big fan of the BBC comedy series
“Monty Python’s Flying Circus”.
- He, with somewhat irrelevant mood, needed a short,
unique, and slightly mysterious name for his invention.
Let’s listen to a more detailed history!
https://www.youtube.com/watch?v=MYpu8Qb3mZw
Python
 Characteristics  Application fields
- Free and open source - Web development
- Easy to learn and read - Data analysis and visualization
- Highly extensible “small core” via modules - Machine learning and AI
- Simple and concise syntax - Game development
- Fast development speed - Desktop GUI programming
- Web scraping

https://www.cleveroad.com/blog/python-vs-swift/
 Drawbacks Python Developers Survey in 2017
- Slow execution speed
- High memory consumption
- Weak in mobile development
(Jave for Android and Swift iOS application)
- Difficult interaction with database
- Easy to cause runtime error
Python’s IDE (Integrated Development Environment)
 A software application that facilitates the efficient development of
other software applications by providing combined developer tools
into a single GUI.
 Aims to maximize programmers’ productivity
(e.g., reduce setup time; debug and edit simultaneously)
 Allows to easily create, edit and execute Python programs
(i.e., files with the .py extension containing codes written in
Python language) => Simple and suitable for beginners!
 Types :
Spyder’s interface
‘The full path of the current file’ must be embedded with or match the ‘Working directory’

Working directory

Explorer options to see


Full path of the defined variables,
current file plots, and files.

Editor
Your code to be
executed in the console
line-by-line Console
Executing your code
(directly or
from the editor)
Spyder installation (via Anaconda)
 Visit the site : https://www.anaconda.com/products/individual
 Choose your version and download it
 Install Anaconda
Spyder installation (via Anaconda) : In progress…
Spyder installation (via Anaconda) : Completed
Check whether you have the Python 3.x version!
 Run Sypder
• Run “Anaconda prompt” >> Write ‘Spyder’ >> Press [Enter] key
• Run “Spyder”
Variables
 A variable : A symbolic name holding values, which are the numeric or text
information.
 Variables do NOT exist until we create them
through assignment in a program.
 A variable is assigned by an equal sign.
• A variable’s name = Information
• Calculation flows move
from the right side to the left of the equal sign.
• The equal sign is NOT used as
mathematical equality.
• Variable’s value is changeable
after its first definition.
Expressions and Operations
 Expressions : the collections of values and variables (and other
items) that are joined together and acted on by operators.
 Arithmetic operators in Python
Operation Symbol Example Solution
Add + 3+5 = ? 8
Subtract - 4-9 = ? -5
Multiply * 8*2 = ? 16
Divide / 15/2 = ? 7.5
Integer divide // 15//2 = ? 7
Exponentiation ** 2**3 = ? 8
Modulus % 14%3 = ? 2
Expressions and Operations (con’t)
 Arithmetic operators in Python (con’t)
• Operators have preference order :
1. Parenthetical blocks
2. Exponentiation
3. Multiplication & Division
4. Addition & Subtraction

• Left-to-right order execution for operations at the same level of priority.

• In-class exercise : In which order should you calculate below expression? Result?
(1+5)*36/3**2
= 6*36/9
= 24
Rules for defining a variable name
 Avoid to include the reserved words (i.e., a set of keywords in Python)

https://www.w3schools.com/python/python_ref_keywords.asp
Rules for defining a variable name (con’t)
 Must start with a letter or underscore _
 Can consist of letters, numbers, or underscores
 Can’t include spacing or a period
• Invalid names : 23cee, cee 23, cee.23
• Valid names : cee23, _CEE
 Case sensitive (i.e., Cee ≠ CEE ≠ cee ≠ cEe)
Take-home points (THPs)
-
-
-
…

You might also like