Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'fop_enqueue_conditional_scripts' not found or invalid function name in /home/skillcu1/datanerds.io/wp-includes/class-wp-hook.php on line 324
Python Variables – Datanerds.io

Python Variables

Python Variables

  • Read
  • Discuss

Think of a variable as a bucket in which you can put anything. Let’s take a bucket and name it “x”, as shown in the figure below. In this bucket, you can put anything you want to; suppose we put “22” inside it. Now, whenever we ask the “x” what is inside you, it will tell us 22

Creating Variables

To declare a variable in Python, you simply need to assign a value to it. For example:

This assigns the value 10 to the variable x. You can then use the variable x to refer to the value 10 throughout your code.

Variable Names

In Python, variable names can contain letters, numbers, and underscores. Variable names are case-sensitive, so x and X are considered to be different variables.

There are a few rules to follow when choosing a variable name:

  • Variable names cannot begin with a number.
  • Variable names should not contain spaces. Use underscores instead (e.g. my_variable).
  • Variable names should not be the same as Python keywords (e.g. for, while, def, etc.).

  Let’s see some more examples of variables.

x = 22
print(x)
y = "Hi! How are you?"
print(y)

Output:

22
Hi! How are you?

In the above code the 

Leave a Reply


Posted

in

by

Tags:

Comments

Leave a Reply