Python-3.4.3/C3/Basic-datatypes-and-operators/English-timed
From Script | Spoken-Tutorial
Revision as of 11:45, 4 June 2019 by Pratik kamble (Talk | contribs)
Time | Narration |
00:01 | Welcome to the spoken tutorial on Data types and operators. |
00:06 | In this tutorial, we will learn about-
Data types in Python like Numbers and Boolean |
00:16 | and Operators in Python like
Arithmetic operators and Boolean operators |
00:25 | To record this tutorial, I am using
Ubuntu Linux 16.04 operating system Python 3.4.3 and IPython 5.1.0 |
00:39 | To practise this tutorial,
you should know how to run basic Python commands on the ipython console. |
00:47 | If not, see the relevant Python tutorials on this website. |
00:52 | There are three built-in data types in Python to represent numbers.
int float and complex |
01:01 | Let us start ipython.
Open the terminal. |
01:06 | Type ipython3 and press Enter. |
01:12 | From here onwards, remember to press the Enter key after typing every command on the terminal. |
01:19 | Let's first see about int. Type a is equal to 13 |
01:26 | Type a Now, we have our first int variable a. |
01:32 | To see the type of a, type, type inside parentheses a.This means that a is of integer data type. |
01:42 | There are some functions associated with the int data type to manipulate it. |
01:48 | These can be explored by typing a dot and then press the tab key. Here you can see the list of functions. |
01:58 | int data type can hold integers of any size. |
02:02 | Let us see an example. Type b is equal to 20 times 9 Here we are storing 9, repeated 20 times in b. |
02:15 | Type type inside parentheses b We can see that type of b is integer. |
02:23 | Next we will see about float data type. Type p is equal to 3.141592 |
02:33 | Type type inside parentheses p We can see that type of p is float. |
02:41 | The last data type in the list is complex number. Type c is equal to 3.2 plus 4.6j |
02:51 | It is just a combination of two floats. The imaginary part being defined by j notation instead of i. |
03:00 | Complex numbers have a lot of functions specific to them. Type c dot and then press the tab key. |
03:09 | Let us try some of them. Type c dot real |
03:15 | Type c dot imag |
03:18 | c dot real gives the real part and c dot imag gives the imaginary part of the complex number. |
03:27 | We can get the absolute value of c by typing, abs inside parentheses c |
03:35 | Python also has Boolean as a built-in type. To try it out, just type, t is equal to True, T in capital |
03:47 | Now you can apply different Boolean operations on t. For example, type f is equal to not t |
03:58 | To see the value of f, type f |
04:03 | Type f or t. The output is True. |
04:10 | Type f and t. The output is False. |
04:16 | What if you want to apply one operator before another? |
04:21 | We can use parentheses for precedence. Let us write a small code to check this out.
Type, a is equal to False |
04:33 | Type, b is equal to True |
04:37 | Type, c is equal to True |
04:41 | Now we will check how precedence changes with parenthesis. |
04:46 | Let us try two expressions and their evaluations. |
04:51 | Type, inside parentheses a and b or c |
04:57 | This expression gives the value True. |
05:01 | Now type a and inside parentheses b or c It gives the value False. |
05:11 | Let's now look at some operators available in Python3. |
05:16 | Python uses plus sign for addition. Type, 23 plus 74 |
05:24 | Minus sign for subtraction.Type, 23 minus 56 |
05:32 | Asterisk sign for multiplication. Type, 45 asterisk 76 |
05:41 | slash sign for division. Type, 384 slash 16 |
05:51 | Let us move ahead with operators. |
05:55 | Percentage sign for modulo operation. Modulo operator gives reminder value. |
06:03 | Type, 87 percentage sign 6 |
06:08 | Two asterisks for an exponent. Type, 7 asterisk asterisk 8 |
06:17 | In case, we may want to use the current value of variable in which the result is stored in the expression. |
06:25 | We can do that by putting the operator before equal to. |
06:30 | Let us say, a is equal to 73 |
06:35 | Type, a asterisk equal to 34 To see the value of a, type, a |
06:44 | Again we will assign the same value to a by typing, a is equal to 73 |
06:52 | Type, a is equal to a asterisk 34. |
06:58 | Type a You can see that both the expressions are giving the same value. |
07:05 | Pause the video. Try this exercise and then resume the video. Find the square root of 3 using Python. |
07:15 | The solution is on your screen. 3 asterisk asterisk 0.5 gives the square root of 3. |
07:24 | Pause the video. Try this exercise and then resume the video. |
07:30 | Will you get the same value for the below expressions? |
07:34 | Switch to the terminal for the solution. |
07:37 | Type, 3 asterisk asterisk 0.5. This operation gives a float. |
07:45 | Type, 3 asterisk asterisk 1/2 This operation also gives a float, but different value.
Hence, we will not get the same value for the expressions. |
07:59 | To get the same value, type, 3 asterisk asterisk inside parentheses 1/2
We can see that now the values are same. |
08:11 | This brings us to the end of this tutorial. |
08:15 | In this tutorial, we have learnt about,
data types in Python like Numbers and Boolean and |
08:22 | Operators in Python like
Arithmetic Operators and Boolean Operators |
08:28 | Here are some self assessment questions for you to solve
What are the three built-in data types in Python to represent numbers? Which operator is used to find exponent? |
08:42 | And the answers,
1. The built-in data types are int float and complex |
08:51 | 2.**Two asterisks are used to find exponent. |
08:56 | Please post your timed queries in this forum. |
09:00 | Please post your general queries on Python in this forum. |
09:05 | FOSSEE team coordinates the TBC project. |
09:09 | Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.
For more details, visit this website. |
09:20 | This is Priya from IIT Bombay signing off. Thanks for watching. |