Python Variables, Constants and Literals

In this article, you will learn Python variables, lessons, texts, and situations.
change

Table of Contents

  • Variable
    • Declaring Variables in Python
    • Assigning a value to a Variable in  Python
  • Constants
    • Assigning a value to a constant in Python
  • Rules and Naming convention of Variables and Constants
  • Literals
    • Numeric Literals
    • String Literals
    • Boolean Literals
    • Special Literals
    • Literal Collection

Variable:


Most languages, such as "variable", are used to store memory data. Every change must have a special identification known as the name. It helps them think of alternatives as a container to control data revamping the program.
It is not a technique, it can be considered as an effective bag to store the book and the book can be changed at any time.
Note: In Python, they do not choose the value of variables, providing the reference of the product (value) of the variables.

Declaring Variables in Python:


In Python, the variables do not require a statement to protect the memory space. By declaring "variables" or "startup variables" it automatically happens when people sign up for the variable value.

Assigning a value to a Variable in  Python:


You can use placement staff = to define a value change.

Example 1: Identify and evaluate price change:


website = "Apple.com"
 print(website)

Example 2: Change the value of the variable:


website = "Apple.com"
 # assigning a new variable to website
website = "Programiz.com"
 print(website)

Example 3: The value of the variable:


a, b, c = 5, 3.2, "Hello"
print (a)
print (b)
print (c)

Constants:


Further is the type of change that can not be changed. It will help you think about the correct way to keep it up and running properly.
It is not a technique, it can be considered as a permanent stick to store several books and those books that can not be changed when inserted into the bag.

Assigning a value to a constant in Python:


Python, which is usually regular and clearly allocated to the module. In this case, the module is a file containing new variables, functions, etc. it is exported to the important file. In the subject area, routinies are listed in large leaflets that define the words.

Example 4: It describes and sets a constant value:


 PI = 3.14
GRAVITY = 9.8

Rules and Naming convention of Variables and Constants:


1. Make a name meaningful. Thinking, the voice makes something more meaningful than v.
2. Use CamelCase notification to display a variable. From a small letter. For example:

myName
myAge
myAddress

3. Use uppercase letters when possible to find the lessons. For example:

PI
G
MASS
TEMP

4. Never use the features like!, @, #, $,%, Etc.
5. Do not start with the number 1.
6. Cases are posted on the Python module that is not intended to be changed.
7. Regular and changing names must have gender (z) or greater (A to Z) or numbers (0 to 9) or letters (_). For example:

snake_case
MACRO_CASE
camelCase
CapWords

Literals:

Literal is a raw data given in a variable or constant. In Python, there are various types of literals they are as follows:

Numeric Literals:


Census notes are inaccessible. Coincidence words can consist of 3 different types, numbers, and complexity.

Example 5: How to use the Python numerals literature?


a = 0b1010 #Binary Literals
b = 100 #Decimal Literal
c = 0o310 #Octal Literal
d = 0x12c #Hexadecimal Literal
#Float Literal
float_1 = 10.5
float_2 = 1.5e2
#Complex Literal
x = 3.14j
print(a, b, c, d)
print(float_1, float_2)
print(x, x.imag, x.real)

String Literals:


The term words are a series of diagrams in a vertical label. We can do two or two or three different types. His character is a literary character between one or only quotes.

Example 6: How to use the Python stripography?


strings = "This is Python"
char = "C"
multiline_str = """This is a multiline string with more than one line code."""
unicode = u"\u00dcnic\u00f6de"
raw_str = r"raw \n string"
print(strings)
print(char)
print(multiline_str)
print(Unicode)
print(raw_str)

Boolean Literals:


A Boolean lithium can have two values: true or false.

Example 7: How to use the Python Police Policies?


x = (1 == True)
y = (1 == False)
a = True + 4
b = False + 10
print("x is", x)
print("y is", y)
print("a:", a)
print("b:", b)

Special Literals:


Python contains a unique literary meaning. We do so to tell if it is not created.

Example 8: How to use this particular pyramid Python?


drink = "Available"
food = None
 def menu(x):
    if x == drink:
        print(drink)
    else:
        print(food)
menu(drink)
menu(food)

Literal Collection:


There are four different literary genres, literary artists, meaning Dict and literary.

Example 9: How to use Python literature?


fruits = ["apple", "mango", "orange"] #list
numbers = (1, 2, 3) #tuple
alphabets = {'a':'apple', 'b':'ball', 'c':'cat'} #dictionary
vowels = {'a', 'e', 'i' , 'o', 'u'} #set
print(fruits)
print(numbers)
print(alphabets)
print(vowels)

In the program, we presented a list of fruits, quantities, word phrases, and the value of each for the purpose and specific codes.
To find out more about literary information, refer to Python's data type.
To getting expect level training for Python training in your Location – Python training in Chennai | Python training institute in Chennai | Python Course institute in Chennai | Python training in Bangalore | Python training institute in Bangalore Python training in Electronic City Python training in Jaya Nagar | Python training in Pune | Python training institute in Pune | Python training in OMR | Python training in Velachery | Python training in Tambaram Python training in Annanagar | Python training in Marathahalli Python training in Btm | Python Online Training | Online Certification Course Python Course in Chennai Python interview questions and answers | Python tutorials | Python training in Indira Nagar | Python Course in Btm | Python Course in Marathahalli Python training institute in Marathahalli Python course institute in Btm Python course in Electronic City | Python online training in Chennai | Python online training in Bangalore | Python Interview Questions & Answers.

Comments

Popular posts from this blog

Python – Functions

What is Django in python?