4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Python variables in nutshell

Variables are nothing but reserved memory locations to store values.

Python has no command for declaring a variable, unlike any programming language.
variable is created the moment you first assign a value to it.
For example-

x = 5
y = "John"
print(x)
print(y)

Variable Naming convention :

  1. Variable name must starts with letter or underscore.

  2. Variable name cannot start with numbers or any special characters.

  3. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )

  4. Variable names are case-sensitive (age, Age and AGE are three different variables)

Python uses the + character To combine both text and a variable:
Example-

x = "awesome"
print("Python is " + x)

We can also use the + character to add a variable to another variable:

x = "Python is "
y = "awesome"
z =  x + y
print(z)

We cannot combine string and numbers, python will generate error, like following code does :

Example
x = 5
y = "John"
print(x + y)

Python allows you to assign a single value to several variables simultaneously. For example −
a = b = c = 1
a = b = c = 1, 2, "john"

Python has five standard data types −

Numbers
String
List
Tuple
Dictionary

All data types we will cover in comming blogs.

python-training-500x500.png

4 upvotes $0.00

Replies (4)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: