Basics of Python Programming

11 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
€67.09
List Price:  €95.85
You save:  €28.75
£55.67
List Price:  £79.54
You save:  £23.86
CA$100.61
List Price:  CA$143.73
You save:  CA$43.12
A$111.94
List Price:  A$159.93
You save:  A$47.98
S$94.87
List Price:  S$135.54
You save:  S$40.66
HK$544.46
List Price:  HK$777.83
You save:  HK$233.37
CHF 62.54
List Price:  CHF 89.34
You save:  CHF 26.80
NOK kr792.28
List Price:  NOK kr1,131.88
You save:  NOK kr339.60
DKK kr500.54
List Price:  DKK kr715.08
You save:  DKK kr214.54
NZ$123.72
List Price:  NZ$176.75
You save:  NZ$53.03
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,361.37
List Price:  ৳11,945.33
You save:  ৳3,583.95
₹5,945.38
List Price:  ₹8,493.77
You save:  ₹2,548.38
RM315.51
List Price:  RM450.75
You save:  RM135.24
₦108,452.30
List Price:  ₦154,938.50
You save:  ₦46,486.20
₨19,476.23
List Price:  ₨27,824.38
You save:  ₨8,348.15
฿2,393.75
List Price:  ฿3,419.79
You save:  ฿1,026.04
₺2,463.20
List Price:  ₺3,519.01
You save:  ₺1,055.81
B$425.95
List Price:  B$608.53
You save:  B$182.58
R1,281.50
List Price:  R1,830.80
You save:  R549.29
Лв131.12
List Price:  Лв187.32
You save:  Лв56.20
₩101,234.93
List Price:  ₩144,627.53
You save:  ₩43,392.60
₪255.76
List Price:  ₪365.39
You save:  ₪109.63
₱4,117.86
List Price:  ₱5,882.91
You save:  ₱1,765.05
¥10,950.28
List Price:  ¥15,643.93
You save:  ¥4,693.65
MX$1,405.25
List Price:  MX$2,007.58
You save:  MX$602.33
QR255.07
List Price:  QR364.41
You save:  QR109.33
P967.09
List Price:  P1,381.63
You save:  P414.53
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,561.31
List Price:  E£5,087.81
You save:  E£1,526.49
ብር8,934.81
List Price:  ብር12,764.56
You save:  ብር3,829.75
Kz64,250.82
List Price:  Kz91,790.82
You save:  Kz27,540
CLP$69,230.60
List Price:  CLP$98,905.10
You save:  CLP$29,674.50
CN¥510.67
List Price:  CN¥729.56
You save:  CN¥218.89
RD$4,260.81
List Price:  RD$6,087.13
You save:  RD$1,826.32
DA9,439.27
List Price:  DA13,485.25
You save:  DA4,045.98
FJ$162.13
List Price:  FJ$231.62
You save:  FJ$69.49
Q539.13
List Price:  Q770.23
You save:  Q231.09
GY$14,638.94
List Price:  GY$20,913.67
You save:  GY$6,274.72
ISK kr9,737.70
List Price:  ISK kr13,911.60
You save:  ISK kr4,173.90
DH704.21
List Price:  DH1,006.07
You save:  DH301.85
L1,285.64
List Price:  L1,836.70
You save:  L551.06
ден4,129.86
List Price:  ден5,900.06
You save:  ден1,770.19
MOP$560.15
List Price:  MOP$800.26
You save:  MOP$240.10
N$1,288.20
List Price:  N$1,840.36
You save:  N$552.16
C$2,574.79
List Price:  C$3,678.42
You save:  C$1,103.63
रु9,517.84
List Price:  रु13,597.49
You save:  रु4,079.65
S/260.55
List Price:  S/372.23
You save:  S/111.68
K283.74
List Price:  K405.36
You save:  K121.62
SAR262.92
List Price:  SAR375.62
You save:  SAR112.69
ZK1,936.44
List Price:  ZK2,766.46
You save:  ZK830.02
L333.95
List Price:  L477.10
You save:  L143.14
Kč1,686.22
List Price:  Kč2,408.98
You save:  Kč722.76
Ft27,781.13
List Price:  Ft39,689.03
You save:  Ft11,907.90
SEK kr772.16
List Price:  SEK kr1,103.13
You save:  SEK kr330.97
ARS$71,509.21
List Price:  ARS$102,160.40
You save:  ARS$30,651.18
Bs483.51
List Price:  Bs690.76
You save:  Bs207.25
COP$305,137.08
List Price:  COP$435,928.80
You save:  COP$130,791.72
₡35,302.85
List Price:  ₡50,434.81
You save:  ₡15,131.95
L1,776.18
List Price:  L2,537.51
You save:  L761.33
₲545,595.73
List Price:  ₲779,455.88
You save:  ₲233,860.15
$U3,131.93
List Price:  $U4,474.38
You save:  $U1,342.44
zł286.05
List Price:  zł408.66
You save:  zł122.61
Already have an account? Log In

Transcript

Section four. In this section we will cover the following topics, basics of Python programming, typecasting and loops in Python, conditional branching and functions in Python. modules in Python, create a UI with Python, radio basics of Python programming. In this video, we will learn about the need for a programming language, the difference between a compiled and an interpreted language. And later, we compare the text editor with the ID. Then, we will learn variables in Python.

And finally, we will learn the different data types in Python with examples. I think everybody in this country should learn to program a computer said Apple's co founder Steve Jobs because it teaches you How to think learning to code is one of the most profoundly life changing things you can do. Code is a critical layer in our lives that sits between us and the digital world. Learning to use code and hardware is incredibly empowering. It enables you to automate a whole bunch of boring and repetitive tasks in your life, freeing you up to concentrate on the important things. The good news is that you don't need to be a genius to know coding.

Just like don't have to be a genius to read and write. It's actually pretty simple. Once you learn a few simple concepts. We will demystify the whole process of coding in Python, so you can better understand what goes on inside your Raspberry Pi. At the heart of a Raspberry Pi four, there are billions of voltage switches called bits that can be set high and low at superfast speeds. This is the language of the machines.

It takes a very long time to code in this language by humans. This is why we use a coding language that can convert human understandable language to machine language. There are a lot of programming languages out there, and they all offer something special. Python is a great option for beginners. It has an easy to read syntax that's free from clutter. And you don't have to worry about curly braces that come in more complicated languages like Java, and it scales all the way up to industrial, medical and scientific purposes.

So it's ideal for beginners and experts also, depending on the way the code is converted to machine language, programming languages are divided into two compiled language and interpreted language. Python is an interpreted language. That is you write code and then run the program under the hood Translated and runs on the fly. Some languages like C and Java are compiled. That is you write the program, then compile it to get a machine code, then you run the machine code. To know more about this, please check out the resources section.

You don't need to do anything to set up Python on your Raspberry Pi. As it comes pre installed with the operating system. Just open the terminal and enter Python three, we will use Python three as Python two will be out of service in 2020. Here you can see the Python shell symbol where you can type out instructions line by line. Using the shell is known as interactive mode as you can interact directly with the code. This is mainly used to debug and test our instructions.

Generally coders create Python programs with a regular text editor and save the files with.py extension. But as you are a beginner, it's better if you use an IDE, aka integrated development environment. IDE s are an all in one solution that combines a text editor debugger syntax checker autotext complete in many such features. We will use the thorny Python ID to learn Python on the Raspberry Pi four. So let's begin our programming journey with understanding the concept of variables in Python. If you created a science project or experiment, you may have come across variables.

In science, a variable is any factor that you can control, change or mashup. In computer programming, variables are used to store things in your program. In Python, you write the name of a variable than a single equals sign and the word number or object you want. Put in it entered this code directly into the shell, a equals one, b equals two. If you ever want to retrieve the contents stored in the variable, you can do this by just typing the variable name like this. You can also print out the variables by passing them into a print function.

Now let's look at the naming rules for variables. variable names should only have a combination of lowercase uppercase digits, or an underscore. Don't start a variable name with a digit. It can start with a letter or an underscore. variable names are case sensitive. Do not use reserved keywords as variables.

With variables you define the variable once and then use it in your code, then it's ready for changing at any time. This will save a lot of time for the programmers rather than going to each line of the code and modifying it. You can assign multiple values to multiple variables in a single line of instruction. Enter the following in the shell, a comma b comma c equals five comma 3.2 comma inside quotes Hello. Now enter print of A, then print of B, and later print off See, we can assign the same value to multiple variables at once. Also by entering following instruction, x equals y equals Zed equals one.

Now printing each variable Ruby is the same output. Python has five standard data types, numbers, strings, lists, tuple, and dictionary. integer, floating point numbers and complex numbers. All falls under the number data type. Python automatically assigns the correct data type based on the number type. For example, type A equals five in the shell.

Followed by type of a will reveal that it is an integer class. Similarly, check the data type for a equals 2.0 and a equals one plus two J. variables can also be used to contain strings. These are groups of letters and other characters that form words, phrases or other text. Creating a string variable in Python is pretty much the same as creating an integer except you surround the text with single or double quotes. Using double quotes makes it easier to include apostrophes such as print have inside double quotes. Don't worry.be happy this line would break after don't.

If you used single quotes, print of inside single quotes, don't worry.be happy, so use double quotes for now. Next, let's look at lists in Python. list is an ordered sequence of items. It is one of the most used data types in Python, and is very flexible. All the items in a list do not need to be of the same type. declaring a list is pretty straightforward.

Items separated by commas are enclosed within square brackets and assigned to a variable. For example, type the following a equals inside square brackets five comma 10 comma 15 comma 20 comma 25 comma 30 comma 35 inside double code 40. To access an element from the list, let's say to access 15, you would need to enter a inside square bracket to as the list is indexed from zero onwards. Similar to get a slice of this list, you need to use a slicing operator to extract a range of items. For example, to extract First three elements from the list, you should enter a insert brackets zero colon three. This will extract elements from index zero to index two.

Lists are mutable, meaning the value of elements of a list can be altered. For example, if you enter a insert bracket zero equals insert code five, and again access the list you will see that the list was updated with the new entry. tuples are just like lists, but they are immutable. That is, once the tuple is created, it cannot be modified. tuples are used to write protect data. It is defined with parenthesis, instead of square brackets, where items are separated by commas, like shown here.

The same slicing operations of lists are applicable for tuples. Also, the final data type of Python is named a dictionary. It is an ordered A collection of key value pairs will use the key to retrieve the respective value. But no the other way around. It is used when we have a huge amount of data. dictionaries are optimized for retrieving data, we must know the key to retrieve the value in Python.

Dictionaries are defined with curly braces with each item being a pair in the form key colon value, key and values can be of any type. Now create a dictionary as shown here. Now can you guess what will be the output of the square bracket to Yes, it will be an error. If you type the square bracket inside code five, it will give to as the output if you type the square bracket one it will give high as the output. Thus, we have finished an overview of different data types in Python summary. In this video, we have covered the following what is the need for programming language difference between compiled and interpreted language, text editor versus ID variables in Python data types in Python.

In the next video, we will learn about typecasting and loops in Python.

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.