【Python】Variables (1)

【Python】Variables (1)

 All you need to do is print 'Hello, World!'


print("Hello world!")

We can use Colab as we introduced before.


What is the way to use variables?

We can use a variable and print it, as below.

AI = "AiceXpert"
print(AI)
Here we make AI is a variable.

Regarding variables, there are several key points to consider
Naming Conventions: Variable names can only contain letters, numbers, and underscores, and must start with a letter or an underscore.Variable can't contain spaces.
Case Sensitivity: Python is case-sensitive, meaning that variable and Variable would be considered two different variables.
Reserved Words: Avoid using Python's reserved words (like if, else, while, etc.) as variable names.
Semantic Naming: Choose meaningful variable names to enhance the readability of your code.
Initialization: Make sure to initialize variables before using them.
Dynamic Typing: Although Python is dynamically typed, it's good to be aware of the data type that a variable currently holds to avoid type-related errors.
Global vs. Local Variables: Understand the scope of the variable (whether it's global or local) and how to use it in different scopes.
Mutable vs. Immutable Types: Be aware of which data types are mutable (like lists and dictionaries) and which are immutable (like integers and strings).
Memory Management: Be mindful of how variables consume memory, especially when working with large data sets.
Multiple Assignments: Python allows for multiple assignments, such as x, y = y, x, but ensure this does not lead to unnecessary confusion or errors.
Using del to Free Variables: If you're certain that a variable will no longer be needed, you can use the del keyword to delete it and free up memory.

Variables are case-sensitive; here is an example


張貼留言

0 留言