88.4k views
4 votes
List the rules involved in declaring variables in python . Explain with examples

User Xxi
by
7.5k points

1 Answer

7 votes

In Python, variables are used to store values. To declare a variable in Python, you need to follow a few rules:

1. The variable name should start with a letter or underscore.

2. The variable name should not start with a number.

3. The variable name can only contain letters, numbers, and underscores.

4. Variable names are case sensitive.

5. Avoid using Python keywords as variable names.

Here are some examples of variable declaration in Python:

1. Declaring a variable with a string value

  • message = "Hello, world!"

2. Declaring a variable with an integer value

  • age = 30

3. Declaring a variable with a float value

  • temperature = 98.6

4. Declaring a variable with a boolean value

  • is_sunny = True

User That Dave Guy
by
7.5k points

No related questions found