Bạn đang xem thử công khai

Đăng nhập để lưu tiến độ, làm bài tập, thảo luận và nhận phản hồi.

Đăng nhập
Module 1: Fundamentals of Python Programming

Variables, Data Types, and Operators

Variables, Data Types, and Operators

Review lesson. A summary table of the variables, data types, and operators part of Module 1, for quick lookup and self-checking after studying units 1.2 → 1.6. If anything is still unclear, go back to the corresponding unit and rewatch the video.

Data types

TypeExampleOrderedMutableNotes
int, float42, 3.14——/ always gives a float, // is floor division
str'Python'YesNoIndexing starts at 0, slice s[a:b] stops before b
boolTrue, False——True + True equals 2
list[1, 2, 3]YesYesb = a does not copy; use a.copy()
tuple(1, 2)YesNoA single element needs a comma: (50,)
set{1, 2, 3}NoYesDuplicate elements are not allowed
dict{"a": 1}YesYesKeys are unique; d.get(k, default) does not raise an error when the key is missing

Operators and precedence

From highest to lowest: ** → * / % // → + - → comparison → is, in → not and or.

Four easily confused points

  • input() always returns a string; to do arithmetic you must convert the type: int(input(...)).
  • == compares values, is checks for the same object (commonly used for None).
  • Falsy values: False None 0 0.0 '' [] () {} set(); the string "False" is still truthy.
  • int(3.99) is 3 — int() truncates the decimal part, it does not round.

Key points

  • Variables/functions use snake_case, constants use UPPER_SNAKE_CASE, classes use PascalCase.
  • Mutable types (list, set, dict) and immutable types (str, tuple) determine how they behave when assigned and passed into functions.