Lesson 3 Variable types in Python

8 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.25
List Price:  €91.79
You save:  €27.53
£55.26
List Price:  £78.95
You save:  £23.68
CA$95.30
List Price:  CA$136.16
You save:  CA$40.85
A$104.44
List Price:  A$149.21
You save:  A$44.76
S$94.20
List Price:  S$134.58
You save:  S$40.38
HK$546.10
List Price:  HK$780.18
You save:  HK$234.07
CHF 63.82
List Price:  CHF 91.18
You save:  CHF 27.35
NOK kr751.73
List Price:  NOK kr1,073.95
You save:  NOK kr322.21
DKK kr480.45
List Price:  DKK kr686.39
You save:  DKK kr205.93
NZ$114.09
List Price:  NZ$162.99
You save:  NZ$48.90
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,153.02
List Price:  ৳11,647.67
You save:  ৳3,494.65
₹5,830.20
List Price:  ₹8,329.22
You save:  ₹2,499.01
RM328.07
List Price:  RM468.70
You save:  RM140.62
₦102,885.30
List Price:  ₦146,985.30
You save:  ₦44,100
₨19,393.48
List Price:  ₨27,706.17
You save:  ₨8,312.68
฿2,519.17
List Price:  ฿3,598.96
You save:  ฿1,079.79
₺2,256.71
List Price:  ₺3,224.01
You save:  ₺967.30
B$357.27
List Price:  B$510.40
You save:  B$153.13
R1,282.86
List Price:  R1,832.74
You save:  R549.87
Лв125.91
List Price:  Лв179.88
You save:  Лв53.96
₩94,793.75
List Price:  ₩135,425.45
You save:  ₩40,631.70
₪258.47
List Price:  ₪369.26
You save:  ₪110.78
₱4,048.92
List Price:  ₱5,784.42
You save:  ₱1,735.49
¥10,895.69
List Price:  ¥15,565.94
You save:  ¥4,670.25
MX$1,162.43
List Price:  MX$1,660.69
You save:  MX$498.25
QR253.91
List Price:  QR362.75
You save:  QR108.83
P943.39
List Price:  P1,347.76
You save:  P404.36
KSh9,085.75
List Price:  KSh12,980.20
You save:  KSh3,894.45
E£3,276.75
List Price:  E£4,681.28
You save:  E£1,404.52
ብር3,999.12
List Price:  ብር5,713.27
You save:  ብር1,714.15
Kz59,421.51
List Price:  Kz84,891.51
You save:  Kz25,470
CLP$62,605.89
List Price:  CLP$89,440.82
You save:  CLP$26,834.93
CN¥505.55
List Price:  CN¥722.24
You save:  CN¥216.69
RD$4,078.44
List Price:  RD$5,826.59
You save:  RD$1,748.15
DA9,423.52
List Price:  DA13,462.75
You save:  DA4,039.23
FJ$155.95
List Price:  FJ$222.79
You save:  FJ$66.84
Q540.94
List Price:  Q772.81
You save:  Q231.86
GY$14,566.49
List Price:  GY$20,810.17
You save:  GY$6,243.67
ISK kr9,646.55
List Price:  ISK kr13,781.37
You save:  ISK kr4,134.82
DH693.20
List Price:  DH990.33
You save:  DH297.13
L1,231.95
List Price:  L1,760
You save:  L528.05
ден3,957.99
List Price:  ден5,654.52
You save:  ден1,696.52
MOP$559.54
List Price:  MOP$799.37
You save:  MOP$239.83
N$1,273.79
List Price:  N$1,819.78
You save:  N$545.99
C$2,563.07
List Price:  C$3,661.69
You save:  C$1,098.61
रु9,282.12
List Price:  रु13,260.75
You save:  रु3,978.62
S/260
List Price:  S/371.45
You save:  S/111.44
K270.37
List Price:  K386.26
You save:  K115.89
SAR262.46
List Price:  SAR374.96
You save:  SAR112.50
ZK1,777.13
List Price:  ZK2,538.86
You save:  ZK761.73
L320.28
List Price:  L457.57
You save:  L137.28
Kč1,590.03
List Price:  Kč2,271.57
You save:  Kč681.54
Ft24,904.88
List Price:  Ft35,579.92
You save:  Ft10,675.04
SEK kr750.08
List Price:  SEK kr1,071.59
You save:  SEK kr321.50
ARS$61,703.42
List Price:  ARS$88,151.52
You save:  ARS$26,448.10
Bs481.07
List Price:  Bs687.27
You save:  Bs206.20
COP$266,463.69
List Price:  COP$380,678.73
You save:  COP$114,215.04
₡35,632.87
List Price:  ₡50,906.29
You save:  ₡15,273.41
L1,723.87
List Price:  L2,462.78
You save:  L738.91
₲521,670.94
List Price:  ₲745,276.15
You save:  ₲223,605.20
$U2,715.34
List Price:  $U3,879.22
You save:  $U1,163.88
zł274.22
List Price:  zł391.77
You save:  zł117.54
Already have an account? Log In

Transcript

What does type mean? In Python variables literals and constants have a type. Python knows the difference between an integer and a string. For example, plus means addition for numbers, and concatenation for strings. If you type d d, d is equal to one plus four, and type print DDG you get five as a result, if you type e is equal to Hello, plus there, print E, it will result and Hello there. Python knows each type that is available.

Some operations are prohibited. It is not possible to add one to string, we can ask Python for the type of something using the function type. E is Hello plus there. If you type E is equal to E plus one arrow will appear. Since it is not possible to add numbers to strings, you can only add one to the E string. If you put it in parentheses, type off he will give you type string.

If you type Hello, type off he will give type string, just like type Hello. Just like type Hello. Type off one will say that it is an integer. multiple numbers types. numbers have two main types in our integers. For example, negative 14 negative 2.01 100 401,233 float a floating point numbers and have a decimal part.

For example, negative 2.5 0.09 8.6 14.0 float capital i e minus Five four double precision 64 bit 53 bits of binary precision 15 to 17 bits of decimal precision. There are other types of numbers. There are variants of integers and floats. x is equal to one type of x will give integer 10 is equal to 98.6 type of temp will give you float. Pay attention to the accuracy of the float. Calculate in the art epl 0.7 0.8.

Calculate float two to the power of 53 info two to the power of 53 plus one, calculate two divided by three. For accounting calculations. Use the decimal type. The decimal module contains the decimal class. decimal floating point has a default position of 28 digit precision. Lock the passage from flow to decimal.

Do decimal dot get context dot traps. decimal dot float operations is equal to true to fix the precision of the decimals, right? decimal get context. Pay attention to operators implementations. Do you love does not work in the same way for decimal types in Python, you can find examples on the right hand side of the display. First, we define the function that results true or false.

If a number can be divided by two without having a remainder, you can perform tests to see which numbers are divisible by to test the function with decimal decimal negative three, Python maintains consistency and calculating the decimal type. The dash dash sign is division for that divides the first operand by the second. Check the expression x is double equal x double dash divided by y multiplied with y plus x percentage sign modulo y. This is always true even for the decimal type. So dash dash does not work in the same way as for the Python fractions module, this is a module that can be important in Python by writing from fractions import fraction to enter the n divided by D fraction in Python, enter fraction n comma D. You can find some examples with another presentation. Conversion of a type.

When we use integers and floating point numbers and an expansion, integers are implicitly covered to float. We can control this with the integer function int and float. Print float of 99 divided by 100. will result in zero point 99. i is equal to 42 type I will say integer F is equal to float of I print F, we'll say 42.0. type of f, we'll say float. Print one plus two times float of three divided by four minus five will give negative 2.5. Conversion of a string. We can use int and float to do a string to integer conversion, s Val is equal to 123.

Type off as well. We'll say string and arrow is obtained if the string contains no numeric characters, right, I vote is equal to end off swell type of Ivo will say integer print, I vote plus one will give 124. In the case where we defined a string named NSP is equal to Hello Bob. If we write an IV is equal to end of NSV. We will get an error since NSV is a string initially No number, how to accept users input. We can instruct Python to stop and read user data as raw input.

The raw input function returns a string. In Python three, the same can be done with the input function. type name is equal to raw input. Who are you print hello comma name. The result will be hello and then the name convert users inputs. If we want to read a number from the user, we must convert it from string to number with a type conversion function.

I NP is equal to ra under dash input Europe floor question mark us F is equal to IMT imp plus one print us floor. USF will print the floor that the user inserted. Later we will see how to handle bad entries, comments in Python. All of that follows hash sign ignored by Python. What is the use of comments to describe what happens in a code sequence to document who wrote the code or other auxiliary information, disable a line of code, maybe temporarily. Sure, examples of comments, operations on strings.

Some operators apply to strings. Plus implies concatenation. Asterix implies multiple concatenation. Python knows when it processes a string or a number and acts accordingly. Print ABC plus 123 will give ABC 123 wild print Hi, Asterix five will give high high high high high variables with mnemonic names. Since we're able to select the name of a variable.

There are a few good practices to respect. We named the variables so that we can remember what they store mnemonic Equals reminder, this can confuse students because while name variables appear often, so it appears though keyboards. What does this code do? exercise? Write a program that asks the user his hours and his hourly rate in order to calculate the salary, how many hours 35 hourly rate 2.75 pay 96 point 25

Sign Up

Share

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.