Skip to main content

What is python variable?

Have you ever forgotten a birthday of a friend relative?computers
can hold on to that information if we tell them to.computers use variables to store information? like moving boxes. Variables have content and names that tell us what’s inside. In Python, a variable can be used to store the output of a statement in the computer’s memory.
               
                                           A=23

The equals sign is used to assign a value to a variable.
The name of the variable is called its identifier
   FOR ex. Day = “Monday”


Now anytime we mention the day in our code. the computer will know that we're referring to the value “Monday” inside of it. Because day stored the value Monday

So when we code:- print(day)
                    >>>Monday
The value in double quotes like “Hello world” are strings. They can be any sequence of letters, numbers, and other symbols.

Python variable names must follow the following rules:
*********************
********************
1. They must start with a letter or an underscore

2. They must contain only letters, digits or underscores

Comments

Popular posts from this blog

string opperation in python

String operations Words and sentences are collections of characters, and so are Python strings. You can access any character in a Python string using its index, either counting from the beginning or the end of the string. When you start from the beginning, you count from 0. In Python integer indices are zero based. >>> name = “My Name is Mike” >>> name[ 0 ] ‘M’ >>> name[ 1 ] ‘y’ >>> name[ 9 ] ‘s’ >>> name[ - 1 ] ‘e’ >>> name[ - 15 ] ‘M’ >>> name[ 7 ] ‘ ‘s ********************* ******************** Slicing You can take shorter substrings from inside a longer string. This operation is called ‘slicing’. >>> name[ 11 : 14 ] # from 11th to 14th, 14th one is excluded ‘Mik’ >>> name[ 11 : 15 ] # from 11th to 15th, 15th one is excluded ‘Mike’ If you want to check if a string contains a particular substring, you can use the ‘in’ operator. >>> “B...

Basic maths for python

Basic Math Python has a bunch of built-in arithmetic operators. The table below provides a brief comparison of the short notations and their longer equivalents. Assume that initially the following is true: a = 3 . Finding the square root of a number is also easy in Python, but it’s not a built-in language feature. You’ll find out about it later in the book! You can calculate the absolute value of a digit (e.g. |-3|), using abs(). For example, abs(- 3) returns 3. Operators precedence The order of execution of mathematical operations in Python is similar to the order used in conventional mathematics. In maths there are three general operator priority levels: 1. exponents and roots 2. multiplication, division and modulus 3. addition and subtraction Exponents and roots are represented by functions of a standard library in Python and are covered further on in this book. All other priority levels have their own built-in Python operators. Hig...