Python Tutorial 2 What are Variables and Types [w/ subs]



00:00:00 – ok now let's use Python to solve some
00:00:04 – real problems and let's say I want to
00:00:07 – calculate my final grade so the way to
00:00:09 – do it is my face grade times a discount
00:00:13 – the discounts depend on how many
00:00:15 – penalties I have so each for each
00:00:17 – penalty I will get one person off from
00:00:20 – my place we quit and that will calculate
00:00:23 – my final weight so if let's say my
00:00:26 – basically my base Wade is flipping 0 and
00:00:29 – tons my msl get one parties so 1 minus
00:00:32 – zero zero point zero point zero one
00:00:35 – which is one percent it's equal to 99
00:00:37 – percent which is zero point like a not
00:00:39 – so that is to discount so three point
00:00:42 – that's my taking zero that's my Creed
00:00:43 – tons of this car that's my fighting
00:00:46 – weight in the case of if I have one
00:00:48 – penalties so that I bring out so what
00:00:50 – print does is put whatever here into the
00:00:54 – consult so if you run it it will give
00:00:56 – you the result of the tabulation and
00:00:57 – print it into the console if I don't do
00:01:00 – this they will calculate it but nothing
00:01:02 – gonna survive in console so that's why I
00:01:04 – do need to write a print here so now it
00:01:08 – has my grade and now I want to know the
00:01:10 – case if I have two penalties or three
00:01:12 – penalties so what I do is I can you know
00:01:15 – copy paste and two panels in ic 83
00:01:19 – penalty 97 that's the case where I have
00:01:21 – one penalty to penalty three penalties
00:01:23 – so let me calculate it and that is the
00:01:25 – case now here's the thing firstly you
00:01:29 – are the one who wrote write this code so
00:01:30 – you understand what flipping 0
00:01:32 – represents what 0p 99 means but if other
00:01:36 – people coming and read your code they
00:01:38 – were like okay what the h*** is those
00:01:39 – number either mix right this is not self
00:01:42 – explanatory right that you're coming
00:01:44 – anything flipping 0 hemmings you know a
00:01:46 – price for certain products right it does
00:01:49 – how the world they can I think we can 0
00:01:51 – represent week and second problem is
00:01:54 – that let's say I'm making mistakes and
00:01:56 – my paste weed is actually not frequent 0
00:01:59 – my Gris based weight is talking high and
00:02:01 – I would I oh now i need to change each
00:02:04 – single lighter than I need to chain here
00:02:06 – to deny here 23 when I and here to
00:02:09 – believe in that and you check flew
00:02:10 – radical in this case was okay
00:02:12 – things I have the article but imagine
00:02:13 – that I ride a hundred lighter code that
00:02:16 – use will migrate if I make one change
00:02:20 – for where my grade I need to go in and
00:02:21 – change every single one of that which is
00:02:23 – there will be very very painful so the
00:02:26 – way to solve this to problem is to add a
00:02:29 – variables so in this case is great
00:02:32 – that's my variable name and then assign
00:02:34 – value 2.9 so what this means is that
00:02:36 – imagine there is a container now I put
00:02:39 – the data which is 2.9 into this
00:02:41 – container in this container named grid
00:02:44 – so whatever I call grief i use whatever
00:02:47 – in that container so it's 2.9 this
00:02:49 – container so if i use grid instead of
00:02:51 – 2.9 a they will understand okay i'm
00:02:54 – actually using to penang so that is
00:02:56 – variable and then i need to change it
00:02:58 – here to the verbal name so imagine that
00:03:01 – at the beginning i use variable great
00:03:03 – instead of actually handwriting to point
00:03:06 – high and now I make a mistake via my
00:03:08 – grade is actually click on one now it's
00:03:10 – good because i only need to change one
00:03:12 – item code and then I the following just
00:03:15 – gonna take out themselves they're gonna
00:03:16 – use whatever in that container which
00:03:18 – treatment one so now its chest that's
00:03:20 – why it's called variable second benefit
00:03:22 – is now it's now it's much more
00:03:23 – explanatory right now you know okay the
00:03:25 – first factors is great we present great
00:03:28 – it because it's a sweet well the second
00:03:31 – one is not a self-explanatory I don't
00:03:33 – know what is pull 99 actually there is a
00:03:36 – way to make it available but I would not
00:03:38 – talk about here when I we talk our loop
00:03:40 – I'm gonna talk about that further
00:03:42 – explain that in this case just remember
00:03:44 – that when you write variable name it
00:03:45 – become even more self explanatory so
00:03:47 – even if you only need to write degree
00:03:50 – once chocolate with stuff once using
00:03:52 – once i still recommend using a variable
00:03:55 – because it's just more experiment or e
00:03:56 – okay secondly I want to talk about the
00:03:59 – rules of making variable names because I
00:04:01 – knew you just you can make it great you
00:04:03 – can use whatever then you can either use
00:04:05 – a right if use a here it's to work if
00:04:08 – you run it it's to work it give it give
00:04:11 – to pin one value here but why we use
00:04:13 – word greed rather than the work eh
00:04:15 – because great self explanatory a like
00:04:18 – who the h*** know what a even means
00:04:20 – right if you indicate a you you know you
00:04:22 – can you can you can still have other
00:04:24 – benefit that you have
00:04:26 – like like in this case you know using we
00:04:29 – use the data but it's not self
00:04:31 – explanatory so the convention is always
00:04:34 – use name the variable that's most optics
00:04:37 – ministry and when you name variable will
00:04:40 – get variable name there's also something
00:04:41 – that's mandatory for example you can try
00:04:44 – number the first matter cannot be number
00:04:47 – it can be second letter how however and
00:04:50 – if you want to write some multiple words
00:04:54 – as a variable you need space in between
00:04:57 – for example my grade and I can do
00:04:59 – underscore grid so my grade this
00:05:02 – represented state space so this is the
00:05:06 – way you if you want to write multiple
00:05:08 – word e as a rebel and there's another
00:05:12 – convention is that variable you all use
00:05:15 – lowercase here so there's another
00:05:18 – concept called constants so variable can
00:05:22 – change but constant you better not
00:05:24 – change in because the convention so here
00:05:27 – if you say my grade is to even one in
00:05:28 – like six I can change to do right and
00:05:31 – then whatever following whatever
00:05:32 – following this whatever falling like six
00:05:35 – degree based on two if you run it this
00:05:38 – way based on two not frequent what also
00:05:40 – they use the same variable net so it
00:05:41 – change the value in the container that's
00:05:44 – why the following church but whatever
00:05:45 – above this set by six it using the 01
00:05:48 – because you define here so that's it's
00:05:50 – changeable a constant is you not you
00:05:54 – better not change it's not mandatory you
00:05:56 – can change somehow but its convention
00:05:58 – it's a protocol you better not edgy so
00:06:00 – if you're using constant you need to
00:06:02 – catalyze everything I said wait to
00:06:04 – catalyze oops so capitalized and here
00:06:07 – it's catalyzed so if you using a
00:06:10 – constant it means that this one you the
00:06:13 – following code you will now make a
00:06:14 – change for that variable okay let's talk
00:06:16 – about data type so they are generally
00:06:19 – for type data type in Python so one is
00:06:21 – called integer it's the number that has
00:06:24 – no decimal point the second one is
00:06:26 – called float that's the number that with
00:06:28 – decimal point and the third one is Latin
00:06:31 – words right it's costly and notice that
00:06:34 – you need to have a quotation mark around
00:06:36 – the words
00:06:38 – because as you can see you in when you
00:06:41 – write code you have variable nets and
00:06:43 – those are also words you don't want to
00:06:45 – confuse I street that's why we need to a
00:06:47 – quotation mark to indicate the word
00:06:49 – sentences or letters here actually
00:06:52 – string are actually data now variable
00:06:54 – name but fourth type of data is called
00:06:56 – boolean so it's a type of data that can
00:06:58 – only has two values either true or false
00:07:00 – Oh of 0 1 so it's two values so in this
00:07:03 – case you need to write two offers as a
00:07:05 – boolean value so here I give you example
00:07:08 – for example I have a variable named call
00:07:11 – number it's 12 14 you know I brigade to
00:07:15 – numb just number so this number is 12 14
00:07:18 – float away right flow it's also you know
00:07:21 – pie it's 3 pin 14 it has a something
00:07:24 – with decimal point and an end amok just
00:07:28 – remember the quotation mark and then now
00:07:31 – you have a boolean value let's say
00:07:32 – whether I pass the exam is passed that's
00:07:34 – the variable and pass its troops oh I
00:07:36 – right catalyst deep too it has to be
00:07:39 – catalyzed if you lower case it it will
00:07:43 – not make that so so your arrow it you
00:07:45 – can write you have to write catalyzed in
00:07:47 – order to wreck being recognized as one
00:07:49 – of the data type so now is fine but
00:07:51 – there's nothing to console because you
00:07:52 – never cleaned out anything so you can
00:07:54 – check it out by let's say printer you
00:07:56 – can check you out mark weather is passed
00:08:00 – I can print its past but here i can buy
00:08:03 – a comma and then it's past so this is a
00:08:06 – variable this is another variable so
00:08:08 – comma separated and also the comma also
00:08:11 – at a spacing between for example this
00:08:12 – case there's a space here so here man
00:08:16 – and it's past if i wreck if i do it
00:08:18 – another night it would has a light break
00:08:21 – here so if i don't like this this way it
00:08:23 – will break into two like this so that it
00:08:27 – that is the way how that's multiple kind
00:08:30 – of data that you can use thank you for
00:08:32 – watching see you next fall
00:08:37 – you


Video Url:
http://youtu.be/0-kkqKfQbM8

Comments

comments