Apuntes
Sin título
Contenido del apunte (2)
Página 1
Página 2
1. Python Interpreter:
Python uses an interpreter, allowing you to write and execute code interactively. You can access the Python interpreter by typing python in your terminal or command prompt.
2. Basic Syntax:
Comments: Denoted by #. Comments are ignored during execution and used for documentation.
Variables: No need to declare types explicitly. Just assign a value to a variable (x = 5).
Print Function: print() displays output. It can take variables, strings, numbers, or expressions.
3. Data Types:
Integers: Whole numbers (5, 10, -3).
Floats: Decimal numbers (3.14, 2.718).
Strings: Textual data ("Hello", 'Python').
Booleans: True or False.
Lists: Ordered collections ([1, 2, 3]).
Tuples: Immutable ordered collections ((1, 2, 3)).
Dictionaries: Key-value pairs ({'name': 'Alice', 'age': 25}).
4. Basic Operations:
Arithmetic: Addition +, Subtraction -, Multiplication *, Division /, Modulo %, Exponent **.
Comparison: Equal ==, Not equal !=, Greater than >, Less than <, etc.
Logical Operators: and, or, not.
5. Control Flow:
Conditionals: if, elif, else for decision-making.
Loops: for loop for iterating over sequences, while loop for repeated execution based on a condition.
6. Functions:
Defining Functions: def keyword followed by the function name and parameters.
Return Statements: return statement to send a value back from a function.
Example:
Here's a simple Python script:
pythonCopy code
# Define a function def greet(name): return f"Hello, {name}!" # Call the function user = "Alice" message = greet(user) print(message)
This script defines a function called greet() that takes a name parameter and returns a greeting message. It then calls the function with the user variable as an argument and prints the result.
Tips:
Indentation: Python uses indentation (4 spaces by convention) to indicate blocks of code.
Readability: Python emphasizes readable code. Use descriptive variable names and follow PEP 8 style guide for clean code.
1. Python Interpreter:
Python uses an interpreter, allowing you to write and execute code interactively. You can access the Python interpreter by typing python in your terminal or command prompt.
2. Basic Syntax:
Comments: Denoted by #. Comments are ignored during execution and used for documentation.
Variables: No need to declare types explicitly. Just assign a value to a variable (x = 5).
Print Function: print() displays output. It can take variables, strings, numbers, or expressions.
3. Data Types:
Integers: Whole numbers (5, 10, -3).
Floats: Decimal numbers (3.14, 2.718).
Strings: Textual data ("Hello", 'Python').
Booleans: True or False.
Lists: Ordered collections ([1, 2, 3]).
Tuples: Immutable ordered collections ((1, 2, 3)).
Dictionaries: Key-value pairs ({'name': 'Alice', 'age': 25}).
4. Basic Operations:
Arithmetic: Addition +, Subtraction -, Multiplication *, Division /, Modulo %, Exponent **.
Comparison: Equal ==, Not equal !=, Greater than >, Less than <, etc.
Logical Operators: and, or, not.
5. Control Flow:
Conditionals: if, elif, else for decision-making.
Loops: for loop for iterating over sequences, while loop for repeated execution based on a condition.
6. Functions:
Defining Functions: def keyword followed by the function name and parameters.
Return Statements: return statement to send a value back from a function.
Example:
Here's a simple Python script:
pythonCopy code
# Define a function def greet(name): return f"Hello, {name}!" # Call the function user = "Alice" message = greet(user) print(message)
This script defines a function called greet() that takes a name parameter and returns a greeting message. It then calls the function with the user variable as an argument and prints the result.
Tips:
Indentation: Python uses indentation (4 spaces by convention) to indicate blocks of code.
Readability: Python emphasizes readable code. Use descriptive variable names and follow PEP 8 style guide for clean code.
Información
- Descripción
- Information Technology Apunte sobre Sin título, creado por Pradeep k el 17/11/2023.
- Creado por
- Pradeep k
- Visitas
- 0
- Valoración