Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python For Beginners, Summaries of Programming Languages

Python language for beginners - Daff

Typology: Summaries

2023/2024

Uploaded on 07/25/2024

do-ky-duy-fgw-dn
do-ky-duy-fgw-dn 🇻🇳

2 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Variable And Data Types: a container for a value. Behaves
as the value that it contains
Primitive (Fundamental) Data Types: represent simple values.
These data types are the most basic and essential units used to
store and manipulate information in a program. They translate
directly into low-level machine code.
- String (str): Represents sequences of characters. Should be enclosed in
quotes.
Example: "Hello, Python!"
Strings are used for text manipulation and representation.
- Integer(int): Represents whole numbers without decimals.
Example: 31
- Float (float): Represents numbers with decimals.
Example: 3.14
Integers and floats are essential for numerical calculations.
- Boolean (bool): Represents either True or False.
Booleans are employed in logical operations and decision-making.
Non-Primitive (Composite) Data Types: are structures that
can hold multiple values and are composed of other data types,
including both primitive and other composite types. Unlike
primitive data types, non-primitive types allow for more complex
and structured representations of data.
- List (list): Represents an ordered and mutable (có thể thay đổi) collection of
values.
Example: fruits = ["apple", "banana", "cherry"]
Lists: Useful when you need a collection that can be altered during the
program's execution, such as maintaining a list of items that may
change over time.
- Tuple (tuple): Represents an ordered and immutable collection of values.
pf3
pf4

Partial preview of the text

Download Python For Beginners and more Summaries Programming Languages in PDF only on Docsity!

Variable And Data Types : a container for a value. Behaves

as the value that it contains

Primitive (Fundamental) Data Types: represent simple values.

These data types are the most basic and essential units used to

store and manipulate information in a program. They translate

directly into low-level machine code.

  • String (str): Represents sequences of characters. Should be enclosed in quotes. Example: "Hello, Python!"  Strings are used for text manipulation and representation.
  • Integer(int): Represents whole numbers without decimals. Example: 31
  • Float (float): Represents numbers with decimals. Example: 3.  Integers and floats are essential for numerical calculations.
  • Boolean (bool): Represents either True or False.  Booleans are employed in logical operations and decision-making.

Non-Primitive (Composite) Data Types: are structures that

can hold multiple values and are composed of other data types,

including both primitive and other composite types. Unlike

primitive data types, non-primitive types allow for more complex

and structured representations of data.

  • List (list): Represents an ordered and mutable (có thể thay đổi) collection of values. Example: fruits = ["apple", "banana", "cherry"]  Lists: Useful when you need a collection that can be altered during the program's execution, such as maintaining a list of items that may change over time.
  • Tuple (tuple): Represents an ordered and immutable collection of values.

Example: coordinates = (3, 7) (toa do)  Tuples: Suitable when you want to ensure that the data remains constant and cannot be accidentally modified. Often used for representing fixed sets of values.

  • Dictionary (dict): Represents an unordered collection of key-value pairs. Example: person = {"name": "Alice", "age": 25, "is_student": True}  Dictionaries: Ideal for scenarios where data needs to be associated with specific labels or keys. They offer efficient data retrieval based on these identifiers.

Arithmetic Operators:

 Addition (+): Adds two operands.  Subtraction (-): Subtracts the right operand from the left operand.  Multiplication (): Multiplies two operands.  Division (/): Divides the left operand by the right operand (always returns a float).  Modulus (%): Returns the remainder of the division of the left operand by the right operand. (tìm số dư của phép chia)  Exponentiation (*)(lũy thừa): Raises the left operand to the power of the right operand.

Conditional Statements (if, elif, else)

  • Conditional statements are used when you want to execute different blocks of code based on certain conditions.

Conditional Statement Example

age = 20 if age < 18 : print("You are a minor.") elif 18 <= age < 21 : print("You are an adult, but not yet allowed to drink.") else: print("You are a legal adult.")

Loops (for and while)

The code above contains a simple Python function called greet(). When 'called' or 'invoked', this function prints "Hello, World!" to the console.