Lesson 2 Constants, Variables, Expressions, Instructions in Python

8 minutes
Share the link to this page


In this video, we will discuss about constants, variables, expressions, and instructions. Number one, constants. fixed values such as numbers, letters and strings are called constants, because their value does not change. constants that contain numeric values can be written in any way our string constants use the single or double dash apostrophe. For example, writing print 123 in double apostrophes will result in the number 123 displayed on the screen writing, print 98.6 will result in 98.6. Writing, print HelloWorld, or result and the text hello world written on the screen.

These examples are for Python two, and Python three, you need to write print, then open parentheses, write the value and end the parentheses number two variables variable is a name stored in the computer's memory where a programmer can store data and then we track the data using the name of the variable. It is up to the programmers to choose the name of the variable. It is possible to change the contents of a variable during a subsequent assignment that's defined, x is equal to 12.2 and y is equal to 14, we can redefine X to have a new value of 100. A writing x is equal to 100. After the initial definition of x. Rules for naming Python variables, it may begin with a letter or under dash.

It should not begin with numbers or special characters. It may contain letters, numbers, and underlines. They're sensitive to the shift lowercase good examples are spam, x, spam 23 underlined speed. bad examples are 2030 spam, number, sign, sign or bar.com. These are different variables, uppercase spam, and all caps bound because of the fact that they're written in different casing reserved words, you cannot take the reserved words as variables or identifier names. These are and doubt for his race assert LS from lamda return break out global not try class except if or while continue access import past yield to find Finally, in print as at work phrases or lines, assignment instructions, x is equal to two is an assignment instruction assigning an expression x is equal to y plus two instructions to print on screen, print x and Python two, print uppercase x in Python two Print lowercase x and Python three assignment instructions, we assign a value to a variable with an assignment statement, equal sign, and assignment statement consists of an expression on the right side, and a variable to store the result.

X is equal to 3.9 times x times one minus x, the expression is on the right. Once it is evaluated, the result is assigned to x. The variable is a memory allocation used to store a value. For example, 0.6. The value stored in a variable can be updated by replacing the previous value 0.6 with the new value 0.93 x is equal to 3.9 times x times one minus x. Number three digital expressions.

Due to the lack of mathematics symbols on computer keyboards, we use apostrophe computer dialect to explain Classical mathematical operations, the Asterix is multiplication, the exponent elevation to power is expressed differently than in mathematics. You can find in the table the meaning of each of the signs. Here's some examples. Type x is equal to two, hit enter, then type x is equal to x plus two and hit enter. Then print x, you will get four. Type y is equal to 440 times 12.

Hit Enter and type print y. The result is 5200 ad type that is equal to y over 1000. Print that it entered, the result is five. Type j is equal to 23. Hit Enter k is equal to j percentage sign modulo five. Print Okay, hit enter The result is three type print for Asterix Asterix to the power free evaluation order.

When we chain operations together, Python must know their processing order. This is called Operation parity. Which operation has priority over others. x is equal to one plus two times three minus four, divided by five, Asterix Asterix six operations priority roads, operators priority rules, rule from highest to lowest priority. Number one, parentheses are always respected. Number two, the exponent elevation to power.

Number three, multiplication, division, interest. Number four, addition and subtraction from left to write. One plus two Asterix Asterix to the power of three divided by Four, multiplied by five is equal to one plus eight divided by four, multiplied by five is equal to one plus two, multiplied by five is equal to one plus 10 is equal to 11. So if you type x is equal to one plus two, Asterix, Asterix three, dash four, Asterix five, then hit enter and type print capital X. The result is 11. Operators priority recommendations.

Remember the rules from top to bottom. When writing code, use parentheses. When you write code, keep the mathematical expressions simple enough to be understood. decompose long series of mathematic operations to make them more readable. The whole division in Python to a strange the whole division truncates the decimal type run 10 dash two, hit enter for those five type print nine dash two results is four Type print 99 dash 100 result is zero floating point divisions produced floating point numbers. This is valid in Python two and Python three, the results will be accurate.

Type print 10.0 dash 2.0 result as 5.0. Type print nine 9.0 dash 100.0 result is zero point 99 integer and floating point mixing, when you perform an operation, where an operand is an integer and the other operand is a floating point, the result is a floating point the integer is converted to a floating point before performing the operation. Type print 99 dash 100 is all the zero type print any nine dash 100.0 result is zero point 99. The Type 99.0 dash 100 The result is zero point 99. If you type point one plus two times three divided by 4.0 minus five. The result is negative 2.5.

Sign Up


Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.