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
€65.30
List Price:  €93.30
You save:  €27.99
£55.85
List Price:  £79.79
You save:  £23.94
CA$95.55
List Price:  CA$136.51
You save:  CA$40.95
A$106.62
List Price:  A$152.32
You save:  A$45.70
S$95.18
List Price:  S$135.97
You save:  S$40.79
HK$547.80
List Price:  HK$782.61
You save:  HK$234.80
CHF 63.79
List Price:  CHF 91.14
You save:  CHF 27.34
NOK kr769.72
List Price:  NOK kr1,099.65
You save:  NOK kr329.92
DKK kr487.07
List Price:  DKK kr695.84
You save:  DKK kr208.77
NZ$117.16
List Price:  NZ$167.38
You save:  NZ$50.21
د.إ257.06
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,690.80
List Price:  ৳10,987.33
You save:  ৳3,296.53
₹5,841.61
List Price:  ₹8,345.51
You save:  ₹2,503.90
RM333.81
List Price:  RM476.90
You save:  RM143.08
₦92,745.84
List Price:  ₦132,499.74
You save:  ₦39,753.90
₨19,508.81
List Price:  ₨27,870.93
You save:  ₨8,362.11
฿2,590.69
List Price:  ฿3,701.15
You save:  ฿1,110.45
₺2,265.11
List Price:  ₺3,236.01
You save:  ₺970.90
B$358.13
List Price:  B$511.64
You save:  B$153.51
R1,311.83
List Price:  R1,874.13
You save:  R562.29
Лв127.74
List Price:  Лв182.50
You save:  Лв54.75
₩96,362.95
List Price:  ₩137,667.26
You save:  ₩41,304.30
₪263.40
List Price:  ₪376.30
You save:  ₪112.90
₱4,038.52
List Price:  ₱5,769.57
You save:  ₱1,731.04
¥10,910.67
List Price:  ¥15,587.34
You save:  ¥4,676.67
MX$1,198.75
List Price:  MX$1,712.57
You save:  MX$513.82
QR255.51
List Price:  QR365.03
You save:  QR109.52
P964.58
List Price:  P1,378.03
You save:  P413.45
KSh9,448.65
List Price:  KSh13,498.65
You save:  KSh4,050
E£3,349.02
List Price:  E£4,784.52
You save:  E£1,435.50
ብር4,021.76
List Price:  ብር5,745.61
You save:  ብር1,723.85
Kz58,375.85
List Price:  Kz83,397.65
You save:  Kz25,021.80
CLP$66,547.19
List Price:  CLP$95,071.49
You save:  CLP$28,524.30
CN¥506.87
List Price:  CN¥724.13
You save:  CN¥217.26
RD$4,108.14
List Price:  RD$5,869.02
You save:  RD$1,760.88
DA9,408.68
List Price:  DA13,441.55
You save:  DA4,032.87
FJ$157.85
List Price:  FJ$225.51
You save:  FJ$67.66
Q545.03
List Price:  Q778.65
You save:  Q233.61
GY$14,660.48
List Price:  GY$20,944.44
You save:  GY$6,283.96
ISK kr9,815.39
List Price:  ISK kr14,022.59
You save:  ISK kr4,207.20
DH707.84
List Price:  DH1,011.24
You save:  DH303.40
L1,238.76
List Price:  L1,769.74
You save:  L530.97
ден4,020.67
List Price:  ден5,744.06
You save:  ден1,723.39
MOP$565.05
List Price:  MOP$807.26
You save:  MOP$242.20
N$1,322.15
List Price:  N$1,888.87
You save:  N$566.71
C$2,578.94
List Price:  C$3,684.35
You save:  C$1,105.41
रु9,342.64
List Price:  रु13,347.21
You save:  रु4,004.56
S/263.24
List Price:  S/376.08
You save:  S/112.83
K270.50
List Price:  K386.44
You save:  K115.94
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,856.98
List Price:  ZK2,652.95
You save:  ZK795.96
L324.92
List Price:  L464.20
You save:  L139.27
Kč1,643.69
List Price:  Kč2,348.23
You save:  Kč704.54
Ft25,598.69
List Price:  Ft36,571.12
You save:  Ft10,972.43
SEK kr764.15
List Price:  SEK kr1,091.69
You save:  SEK kr327.54
ARS$61,224.11
List Price:  ARS$87,466.76
You save:  ARS$26,242.65
Bs485.98
List Price:  Bs694.29
You save:  Bs208.30
COP$277,111.33
List Price:  COP$395,890.30
You save:  COP$118,778.96
₡35,607.40
List Price:  ₡50,869.89
You save:  ₡15,262.49
L1,730.46
List Price:  L2,472.19
You save:  L741.73
₲521,774.38
List Price:  ₲745,423.92
You save:  ₲223,649.54
$U2,704.33
List Price:  $U3,863.50
You save:  $U1,159.16
zł282.40
List Price:  zł403.45
You save:  zł121.04
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.