Skip to main content
ALEXA

ALEXA

AWAKE AND AWARE

project name
project detailed description
link name
link detailed description
book name
Detailed description of the book
article name
Detailed description of the article
friend name
Detailed description of friend
custom item
custom item
Detailed description of this custom item
bool

1. Boolean Values

Meaning: Represents true or false in judgments, generally used in conditional tests.

a = True
print(a)
print(10 < 5)
print(10 > 8)

# output
True
False
True

AlexaOriginal...About 1 minPythonwebtypora
if

AlexaOriginal...Less than 1 minutePythonwebtypora
tuple

1. Creating a Tuple

  • Use parentheses to create a tuple.
  • Separate elements with commas.
tup = (2, "x", "y")
print(tup, type(tup))

# output
(2, 'x', 'y') <class 'tuple'>

AlexaOriginal...About 2 minPythonwebtypora
dictionary

1. How to Create a Phone Book

Suppose we have the following contacts:

Name Phone Number
李雷 123456
韩梅梅 132456
大卫 154389
Mr.Liu 131452
Bornforthis 180595
Alexa 131559

AlexaOriginal...About 5 minPythonwebtypora
set

1. Creating a Set

  1. Directly use curly braces to create.
set1 = {1, 2, 3, 4, 5}

AlexaOriginal...About 1 minPythonwebtypora
list

1. List Structure

  • Use square brackets to represent lists.
  • Elements inside the list are separated by commas.
  • Note that it is in the English input method.

AlexaOriginal...About 9 minPythonwebtypora
Assignment 1

Submission instructions

  1. You should submit your homework on GitHub.
  2. For this assignment you should turn in 4 separate .py files named according to the following pattern: hw1_q1.py, hw1_q2.py, etc.
  3. Each Python file you submit should contain a header comment block as follows:

AlexaOriginal...About 12 minPythonwebtypora
Numeric Type

1. Characteristics of Numeric Types

image-20231222232833034
In [2]: 1+1
Out[2]: 2

In [3]: 1+1.0
Out[3]: 2.0

In [4]: 9-1
Out[4]: 8

In [5]: 9-1.0
Out[5]: 8.0

In [6]: 2*2
Out[6]: 4

In [7]: 2*2.0
Out[7]: 4.0

In [8]: 9/3
Out[8]: 3.0

In [9]: # If one of the numbers is float, the result will be float (highest priority)

In [10]: # Division involves precision issues, so the result is a float

AlexaOriginal...About 5 minPythonwebtypora
Strings

1. Definition of Strings

A string is a sequence composed of letters, numbers, and special characters.

image-20231222232933858

2. Creating Strings

— Using single quotes, double quotes, or triple quotes.


AlexaOriginal...About 12 minPythonwebtypora