GWU ISTM6200 Lecture 2: Python Variables, Expressions, and Statements

Verified

Added on  2021/11/24

|32
|1832
|104
Homework Assignment
AI Summary
This document presents lecture notes from ISTM6200, focusing on fundamental Python programming concepts. It covers variable naming rules, data types (numbers, strings, lists, tuples, and dictionaries), and type conversions. The lecture explains expressions (combinations of constants, variables, and operators), and various operators (arithmetic, comparison, and logical), including operator precedence. It also discusses assignment statements, assignment operators, and multiple assignments. Furthermore, the lecture introduces built-in functions like `print()` and `input()`, providing examples and exercises. The document emphasizes the importance of understanding these concepts for effective Python programming and provides resources for further learning.
Document Page
Prof. Wei Chen (wei_chen@gwu.edu)
Dep. of Information Systems & Technology Management
May 27, 2021
Lecture 2: Variables, Expressions, Statements
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
ISTM6200 / Summer 2021
Class 2: Overview
Learning Objectives:
Be familiar with variable naming rules
Be familiar with the basic data types
Be able to convert data types when necessary
Understand basic expressions and statements
Today’s Agenda:
Recap
Variables and Data Types
Expressions and Statements
Basic Built-in Functions
Document Page
ISTM6200 / Summer 2021
Recap: Python as a Language
Python is an incredibly efficient language: your
program will do more in fewer lines of code than
many other languages would require
We use Python for many purposes:
make games
build web applications
solve business problems (data problems)

The Python community: ask advice from others
who have already solved similar problems
Document Page
ISTM6200 / Summer 2021
Recap: Jupyter Notebook
Create a new python file
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
ISTM6200 / Summer 2021
Recap: Jupyter Notebook
Document Page
ISTM6200 / Summer 2021
Variables
A variable is a name that represents a value
stored in the computer’s memory, i.e., a storage
space with a symbolic name.
X
Variables vs. Constants: Fixed values (e.g.,
numbers, letters, strings) are called ``constant’’
since their values do not change.
The “content” of a variable can be changed:
Example: x = 10
x = “Hello”
print(“The value of x is ”, x)
Document Page
ISTM6200 / Summer 2021
Variables (Cont.)
A variable is created the first time you assign it a value
Variables must be created before they are used.
Assignment statement: assigns a value to a variable.
Syntax: Variable Name = Variable Value.
Example:
In [1]: x = 5
x
Out[1]: 5
In [2]: Class = “ISTM 6200”
Class
Out[2]: ‘ISTM 6200’
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
ISTM6200 / Summer 2021
Naming Conventions
Names can consist letters, numbers and the underscore
character.
Names must begin with a letter, or underscore
character.
Names cannot contain spaces.
Names are case sensitive, e.g., bob Bob BOB
We cannot use one of Python’s keywords as variable
name!
Recommended practices when naming variables:
Meaningful
Succinct
Lowercase, concatenate words with underscore
Document Page
ISTM6200 / Summer 2021
Keywords
Reserved words (keywords) in Python 3
They must be spelled exactly as written here!
Document Page
ISTM6200 / Summer 2021
Exercise: Naming and Using Variables
1) Store a message in a variable, and then print the message
2) Store a message in a variable and print the message. Then
change the value of your variable to a new message, and
print the new message
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
ISTM6200 / Summer 2021
Data Types
Python has five standard data types: numbers,
strings, lists, tuples, and dictionaries.
In Python, we do not need to explicitly define or
declare the type of a variable.
x = 3 implies x is of ?? type
y = “OK” implies y is of ?? type
How to find the type of a variable? type(…)
type(x)
type(y)
Document Page
ISTM6200 / Summer 2021
Basic Data Types in Python
Numbers
Integers: x = 2, y = 5
Floats: x = 3.456, y = 9823.9
Strings
my_name = “Yixin”
my_course = ‘Introduction to Programming’
Lists: e.g., my_lst = [1,2,3, ‘number’]
Tuples: e.g., my_tpl = (1,2,3, ‘abc’)
Dictionaries: e.g., my_dict = {‘name’: ‘Amy’, ‘age’: 18}
chevron_up_icon
1 out of 32
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]