-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariables.py
89 lines (61 loc) · 2.26 KB
/
Variables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#* Variables - Python
# In Python, variables are used to store data. Unlike some languages
# programming that requires explicit type declarations, Python is a dynamically typed language,
# meaning that the type of a variable is automatically inferred based on the value it contains.
# Here is some basic information about variables in Python:
#? Declaration and Assignment of Variables:
# In Python, you do not need to declare the type of a variable before using it. You can assign a value to a
# variable as follows:
#? Assigning a value to a variable
variable_name = 20 #AssignedValue
#? Examples:
# Integers
age = 25
# Floating point (decimal number)
price = 19.99
# Text strings
name = "John"
# Booleans
is_of_age = True
#? Naming Conventions:
# It is good practice to follow naming conventions to make your code more readable. Some
# common conventions include:
#
# - Variables usually have lowercase names.
# - For compound names, the snake_case convention is used (lowercase words separated by hyphens
# low).
full_name = "Juan Perez"
#? Operations with Variables:
# You can perform various operations with variables, depending on their type:
# Operations with numbers
result = age + 5
# Concatenation of text strings
message = "Hello, " + name
# Logical operations with booleans
is_adult = age >= 18
#? Type of data:
# Python supports several data types, including:
# - **int:** Integers
# - **float:** Floating point numbers
# - **str:** Text strings
# - **bool:** Booleans
# - **list:** Lists (mutable sequences)
# - **tuple:** Tuples (immutable sequences)
# - **dict:** Dictionaries (key-value pairs)
# - **set:** Sets (unordered collections of single elements)
#? Complete Example:
# Variable declaration and assignment
name = "Mary"
age = 30
height = 1.75
is_student = False
# Operations with variables
age_in_ten_years = age + 10
greeting = "Hello, " + name
# Print results
print("Name:", name)
print("Age in ten years:", age_in_ten_years)
print("Greeting:", greeting)
# These are just basics about variables in Python. As you progress in your learning,
# you will be able to explore more advanced features and use variables in more complex contexts.
# Have fun programming in Python!