Python fundamentals for Data Science - Part 1 | Data types | Strings | Lists
Key Takeaways
This video series covers Python fundamentals for Data Science, including data types, strings, lists, and basic operations, using tools such as Python, Jupiter notebook, and the print function.
Full Transcript
hello everyone so welcome back to your channel data science with her shed my name is her shitake I'm a data science instructor and mentor so in the previous videos we have seen how to setup your Python environment how to work with different kind of notebooks jobra notebooks google collaboratory and others so now we are all set to dive right into programming and learn Python to get started with data science so I have broken down the Python fundamentals series into three parts and in this video we are going to cover the part one where we going to talk about variables different data types some operators basic operators asthmatic operators as well as some string formatting options and strings of string operators we learn about lists how lists work and what sort of operations can you perform with the Python lists so by the fundamentals part 1 coming right up [Music] now Python is a very simple and very easy to learn language because of its straightforward and explicit syntax now we can use Python we can get started with it without any boilerplate code that we need in other languages like C and C++ so I'm here in my terminal have my Python environment running and I am in this folder be HWH so let's create a new folder new directory for this particular series on fire Python fundamentals okay mkdir pattern fundamentals and let me change the directory to pattern fundamentals all right now the next thing that we need to do is start our Jupiter notebook server so Jupiter notebook and this will take a few seconds to give us the link yeah all right so this is where the server is should be running all right so I am here I do not have anything in this particular path in fundamentals folder since I just created it now the next thing that I need to do is create a part III notebook all right so this has created a new notebook which has been named untitled so let's first change the name of our notebook so this is path in front of my notes part 1 awesome so the name has been changed our notebook is ready to use so the first thing that we do while learning any language any programming language is print hello world so in Python we can use the print function so we have print function which we can use parenthesis now you type in the string that you want to print so hello world so let's run this you can run this by hitting shift press ENTER on your keyboard or the run icon over here so I printed the hello world and this is how this particular cell has given its output now let's say if we talk about input/output so the next thing that we need is to take some input from the user and we can use the input function so this input function prompts the user to enter the value and if I enter something like let's say data science and hit enter simple so this shows me that this is a particular string where it says data science so that was about input/output so Python doesn't use curly braces like other languages it uses indentation to block its code and it accepts both tabs as well as spaces now the standard is that it uses four spaces so let's say I have this variable called a which I assigned the value of five and let's say if I have to add a conditional block it's a check if a equals equals five and then I add a column and a hit enter this gives me four spaces this means that I have entered into this if conditional block now everything that I write inside would be treated under this if conditional block so let's say I print a equals five so this would if I run this I have this equals five printed since the value of a is 5 so you can see that I have four indented spaces too this block of cool now the next thing is different data types so how do you define or how do you find out what the data type of a particular variable is so let's say I have this string called let's say my string and I add hello world to this and I want to know what the data type of my variable is so let's say I let's print the type of my string variable so I can use this type function which gives me which returns the type the data type of that particular variable so if I run this so this has given us class string so this means that my string is a class string object and simply so let's say there is a variable called in which we assign a value of 10 and if it happened the type of n this gives us class int so this is basically an integer class object now let's say there is another number called intrude and to this we assign 7.5 and if I print the type of an underscore float so this is a floating class object and wrote so we've seen string integer float floating point variables so see that in Python we do not have to define the type or the datatype of these variables that this is a string or this is an integer this is a floating point number so python is completely object-oriented and it is not statically typed like other languages plus plus RC when which you have to compile your cool this is a dynamic and interpreted language so we do not have to define the data type of each of these variables and in Python we have two different types of numbers integers and floating point and then we have strengths now to talk about strings we have two ways to define strings now the first is let's say I have single quote strings where let's say I type this is a single code string and I print single code string and this has given me the strength which is this is singly constraint now the other way is to define a double quote string so let's say this is a double quote string and I define it like this so here the difference is that if you want to add an apostrophe so you won't be able to do that so let's say if I want to add M you know write it like it is a single quote string so this will end the string right over here and if you run this this will give you a syntax error so you won't be able to add apostrophe in a single quote string and whereas you will be able to do that in double quote string yeah so it hasn't given you any error and if you print this so you get it's a double quote string so that works just fine for us now let's try to learn about different kind of operation that we can perform on these numbers so let's say I have n 1 e which is let's say it's 5 and then we have n 2 let's assign it 7.5 and now if I want to rent let's say add these two numbers n1 plus n2 so run this shift enter on your keyboard and this has given you 12.5 so I had one integer point variable one floating point variable and when I add them up so this I get is a floating point number 12.5 now let's say I define a new string and a and string and let's put ABC in it and now let's try to add this to a number which is n1 let's say and if we run this so this gives us an error that can only concatenate string and not integer to string so we have we are trying to concatenate we are trying to add an integer to a string so it has given us this type error all right and let's say I have an STR 2 which is BEF and now if I try to add NST R 1 plus and STR to and if I run this so next year 1 okay so let's just rename it ok ok and if I now if I run this so I get a b c d e f so I've got these two strings added concatenated so this is how string addition works now if I want to assign to variables at the same time I can simply do n1 come on to or if you want to swap two numbers you can do that so in n1 I have 5 over here in in n2 I have sell for 5 so let's say I want to throw up these numbers so I simply write n 1 equals n 2 and n 2 equals n separated by comma and now if I want to check n1 it has 7 point 5 inside it so the values have swapped so you can again check and to alright and if you guys want to assign some different values you can also do that so let's say you assign 10 and 11 so now if you just run the Redis you see and one contains 10 which is the first value and 2 is contains 11 which is the corresponding value so this is how you can assign value separated by comma and [Music] so let's look at a few arithmetic operators that we can use so let's say if we can see the damask rule so let's try to evaluate an expression so we have result equals let's say 3 plus 4 point 0 divided by 2 multiplied by 5 now as per the demas rule where we should have the division 4 so the value of this expression should be 4 divided by 2 - 2 into 5 10 10 plus 3 13 now let's try to print the result should get 30 awesome so I have my result as 13 so we can see that there is many corporators plus multiply divide subtract all work as as we expect now the other operator the big news is the modulo operator so this is modulo operator which is denoted by a percentage now let's say this is basically used to calculate the remainder so let's say I want to divide 17 by 10 and find out the remainder so we know that the answer should be 7 so let's look at what it gives us awesome so this remainder or the modulo operator works just fine as expected let's look at other operator which is the power so let's say I want to evaluate an expression expression x raised to the power n so how do I do that in Python so let's say I have x equals 5 n equals 4 and if I want to evaluate X to the power n so all I need to do is X double asterisk and n so this expression is basically X raised to the power n so 5 raised to the power 4 is 625 and if I run this awesome so I have 605 five days to a power of 4 as my answer and if you want to look at how these operators work on strings so let's say I have a string called ABC a b c and if let's say i multiply it by 10 so what do you think should be printed so this is it like ABC into 10 - Willick those in error or what so let's try and run this so this has concatenated 10 ABC strings and these are 10 so in case you want to find out what's the length of a particular string you can use the Elian function so you just need pass on the strain so let's store this and click the string also and if let's run this and if you want to find out what's the length of this answer this is we have 30 so 3 is the length of this NS TR and if you multiply it by 10 it gives us a concatenated string of 10 ABC's and then if you find out the length of answer and this is basically 33 into 10 so length of our answer string is 30 so now let's talk about some string formatting options and operators that we can use to manipulate strings so PI 3 uses C style string formatting to create new at strings so let's say I have a name variable which is a string let's say her shed and I want to print a formatted string where I don't know the name of the person yet so I replace use so this percentage s this is an argument specifier positive s and let's say is date scientist so percentage s is a data scientist and I use to provide the name of the query weight at the end so this is how I format the string so I should have heard is a data scientist as my answer so if you run this do you see the name has been put in place of this argument and I have Hirsch it is a data scientist printed for me now the other operations that you can perform to manipulate your strengths are basically let's say if you want to convert your string to upper case so you can simply use name dot the upper so you can invoke the upper function so this will basically convert your string to upper case so you see that Harshit has been printed capital and in case you want to convert it into lower case you can use the lower function and let's say you have another string NS TR equals it is nice state today so if you have the string so let's say you want to capitalize the string so you can use the capitalize July's function so if you run this so you see that the first letter of the sentence is has been capitalized is converted into uppercase so this I is capitalized so you can use the capitalize function like this now there are other functions so let's talk about string slicing so slicing is an important technique that would use and Python lists as well which we are going to talk about in a bit so let's say you have a strain called name and which is already defined so name in name we have her and in case you find out what you want to find out at which index is s present so you want to find out at which index of this string is as present so this index function basically gives you the index at which the character is present the first appearance of that character so I have s at third position so the indexing of any string starts from 0 on and not 1 so at 0 I have h at work force index I have a second index I have R and s is present at the third index all right now if you talk about slicing so in slicing what you need to do is you need to mention the starting index all right and the ending index so this will basically slice your string from second index up till the fourth index this fifth index is not included so this is excluded so this is how your string is now printed so you can see at second index I have are present and at 4th index third fourth I have h present so our search has been printed for me now in case you want to print to is to 6 but you want to skip a number in between so the you have you can mention the step size by which you want to jump so this will print R and H started from second index and then end it at the 5th index which is this ending index minus 1 and the step size is 2 so it will skip one in between so I started from our skipped is and then printed edge but it has reached the 5th index so the string has ended over here so this is starting index this is my ending index and this is the step size how you want to jump you can mention is 2 3 4 so similar operation you will be performing with less as well in a bit so these are basically the commonly used operations that you would use in string but there would be other operations that you can learn from the official documentation page as you can find in the description below so let's now talk about Python lists now these are very similar to arrays in c c++ but the major difference is that they can contain any type of a variable so let's see how we can define lists so let's say I have my list called a list equals enter 3 comma 4 comma 5 inside of it and if I want to print this list I simply do print a list and this has printed all the variables all basically all the elements of my list now I can do a bunch of tasks and also to see the major difference between these Python lists and the arrays so you can do this and Python lists so let's say I want to store her shed and then I want to store 2 then I want to store 5 point 5 so this is all valid for Python lists sorry friend a list and you see my first element is a string my second element is an integer my third element is a floating-point number so I can use a bunch of functions in the list datatype let's say I want to add or append and but to my list so let's say I want to append ten at the end so if I pan and then let's use a pen a few more 15 then if I print my list I you see 10 and 15 have been added at the end of my list and in case I want to delete or here we use pop function so I can use the pop function and now if I print so this puff function basically deletes or pops out the last element of my list so you see 15 has been deleted from my list now in order to access any element of my list any particular element so let's say so again here the indexing starts from zero so the her shell is basically my zeroth element so if I want to access the first element of my list I would use the 0th index so if I run this I get her which is the first element of my list and similarly if I print food I get a list index out of range because fourth index is not available in my list I only have four elements so the last index would be three so that's how indexing works and similar to strings I can use slicing here as well so I said let's say I want to capture all my elements except the first so all I need to do is simply 1 colon and do not enter anything after that so if you run this so the first element has been skipped since that was the 0 and this is a 2 user so I have 2 second basically the first index the second index in the third index everything after the first index starting index ending in this I have now specified so it will go up till the end so this is how you can use slicing and lists as well another important and interesting thing that you can that you would want to know is that lists can also contain a list inside so let's say you want to append a list at the end so you can also do that so let's see what we'll have if you do that you see a list has been appended at the end as well so my list can have any type of variable inside my list so it's an amazing it's an interesting data structure to work with so if I use a multiplication operator so let's say I multiply out the list by 2 I get so this basically replicates my entire appends the entire list twice so I multiplied it by twice if I would have multiplied it by three so there would have been three replications and similarly I can also perform addition so if I do LS plus a list so this also gives me the same thing so these are a bunch of functions and techniques and operators that you can use to manipulate your list so to wrap it up we've seen what are the different data types and what all different operations that we can perform on them now you can find the link to all the work that we have done i've added the link of my github repository as well as the google collaboratory notebook which you can refer to now your task is to get comfortable with these data types and you know get some hands-on practice using these operators on different sort of data types and I have also added the link to the Python official documentation page so if you want to learn more about different kind of other functions that are available for each of these you can definitely do that and in the next video we're going to talk about loops modules and packages and object-oriented programming and Python so if you liked this video give it a thumbs up feel free to comment down below if you have any concern every any thought any suggestion for the upcoming videos and do not forget to subscribe to the channel so that you don't miss out on the upcoming parts so till then keep learning data science with her thanks
Original Description
This the first part of the 3-part python fundamentals series.
We have covered :
* I/O function and indentation
* Variable and their data types
* Operations on different data types
* String formatting and Operators
* Basic Operators
* Basics of Python Lists
Link to the GitHub repo: t.ly/eZx8b
Link to Google Colab Notebook: t.ly/mZN2g
You can connect with me on:
LinkedIn: https://www.linkedin.com/in/tyagiharshit/
Medium where I -write: https://medium.com/@harshit_tyagi
Instagram(for health and wellness): https://www.instagram.com/upgradewithharshit/?hl=en
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Harshit Tyagi · Harshit Tyagi · 5 of 60
1
2
3
4
▶
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Your PATH to learning Data Science
Harshit Tyagi
Ideal Python environment setup for Data Science projects - Unix shell, Anaconda and Git.
Harshit Tyagi
Building COVID-19 interactive dashboard from Jupyter Notebook | No frontend/backend coding required.
Harshit Tyagi
Introduction to Jupyter Notebooks - Interface | Ipython Kernel | Sharing | GitHub
Harshit Tyagi
Python fundamentals for Data Science - Part 1 | Data types | Strings | Lists
Harshit Tyagi
Python fundamentals for Data Science - Part 2 Dictionaries | Conditionals | Loops | Functions
Harshit Tyagi
Python fundamentals for Data Science - Part 3 OOPS | Working with External Libraries & Modules
Harshit Tyagi
NumPy Essentials for Data Science - part-1 | One Dimensional Array
Harshit Tyagi
NumPy Essentials for Data Science - part-2 | Multi-Dimensional Array
Harshit Tyagi
Math For Data Science | Practical reasons to learn math for Machine/Deep Learning
Harshit Tyagi
Linear Algebra Ep 1 | Introduction to Vectors, Matrices and Tensors using NumPy
Harshit Tyagi
Linear Algebra Ep 2 | Dot Product in Linear Algebra for Data Science
Harshit Tyagi
Python vs R | The BEST programming language for your Data Science Project
Harshit Tyagi
Linear Algebra for Data Science Ep3 | Identity and Inverse Matrices | NumPy
Harshit Tyagi
The Data Show Ep1 | Elucidating Data Science in Drug Discovery - A CTO's Account
Harshit Tyagi
Google Certified TensorFlow Developer | Learning Plan, Tips, FAQs & my Journey
Harshit Tyagi
Speeding up your Data Analysis | Hacks & Libraries
Harshit Tyagi
How to build an Effective Data Science Portfolio
Harshit Tyagi
End-to-End Machine Learning Project Tutorial - Part 1
Harshit Tyagi
Data Preparation with Sci-kit learn and Pandas | End-to-End ML Project Tutorial - Part 2
Harshit Tyagi
Training and Fine-Tuning ML Models with Sklearn | End-to-End ML Project Tutorial - Part 3
Harshit Tyagi
Deploying a Trained ML model via Flask on Heroku | End-to-End ML Project Tutorial - Part 4
Harshit Tyagi
Three Decades of Practising Data Science | Interview with Dean Abbott
Harshit Tyagi
Calculating Vector Norms - Linear Algebra for Data Science - IV
Harshit Tyagi
Ep1 - Getting Started | Zero to Hero in Computer Vision with TensorFlow
Harshit Tyagi
Ep3 - Designing Data Experiments to enhance your Product | Rapido's Data Science Lead, Pramod N
Harshit Tyagi
Building projects with fastai - From Model Training to Deployment
Harshit Tyagi
October AI - Video Calling with One-Tenth of Internet Bandwidth
Harshit Tyagi
November AI - Breakthrough in biology after 50 years | Datasets, books, research papers and more...
Harshit Tyagi
Data Science learning roadmap for 2021
Harshit Tyagi
Talk is cheap, BUILD - Microsoft Software Engineer | Interview with Abhirath Batra
Harshit Tyagi
Building a Habit of Reading Research Papers | Ft. Anurag Ghosh(Microsoft Researcher)
Harshit Tyagi
Tableau vs Python - Building a COVID tracker dashboard
Harshit Tyagi
[Explained] What is MLOps | Getting started with ML Engineering
Harshit Tyagi
Dmitry Petrov - Creator of DVC | ML Systems, Teams, Scaling challenges, and Learning Data Science
Harshit Tyagi
Five hard truths about building a career in Data Science
Harshit Tyagi
Computing gradients using TensorFlow | Training a Linear Regression model from scratch.
Harshit Tyagi
Foundations for Data Science & ML - First steps for every beginner!
Harshit Tyagi
Course Outline - Foundations for Data Science & ML
Harshit Tyagi
How Machine Learning uses Linear Algebra to solve data problems
Harshit Tyagi
Calculus for ML - How much you should know to get started
Harshit Tyagi
Building a buzzing stocks news feed using NLP and Streamlit | Named Entity Recognition & Linking
Harshit Tyagi
AI Engineer - The next big tech role!
Harshit Tyagi
AI researcher vs AI engineer | The next big tech role!
Harshit Tyagi
Reviewing LLMs for content creation
Harshit Tyagi
Building a chatGPT-like bot on WhatsApp #coding #chatgpt #engineering
Harshit Tyagi
High Signal AI - the most action-oriented newsletter on the web! #ai
Harshit Tyagi
Building an AI-powered Discord Chatbot Locally for FREE using Ollama
Harshit Tyagi
Build a second brain with Khoj 🧠 #ai #obsidian #plugins #productivity #engineering #notes
Harshit Tyagi
Summarising YouTube Videos using Ollama on Discord | Becoming an AI Engineer - Ep 2
Harshit Tyagi
Watch the full video on my channel - Roadmap to become an AI Engineer.
Harshit Tyagi
Mesop - Python-based UI framework from Google!
Harshit Tyagi
How I automated my YouTube | Gumloop tutorial | No Code
Harshit Tyagi
ARC PRIZE - Win $1Million to Beat the ARC-AGI benchmark
Harshit Tyagi
Microsoft's Autogen vs CrewAI - tested on a diverse range of use cases
Harshit Tyagi
Claude #AI artifacts are just amazing!
Harshit Tyagi
OpenAI releases CriticGPT to correct GPT-4's mistakes | Read the paper with me
Harshit Tyagi
Day in my life | Vlog #1
Harshit Tyagi
How to add AI Copilot to your application using CopilotKit | Tutorial
Harshit Tyagi
Quick Questions with an AI Founder - Anudeep Yegireddi
Harshit Tyagi
More on: ML Maths Basics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
The Dark Side of AI: What We Lose When We Stop Thinking
Medium · AI
AI Security Isn't a Product. It's an Engineering Discipline.
Dev.to AI
Why Solving Legal AI's Context Problem Is Harder Than You Think
Forbes Innovation
How Can We Truly Protect Information Privacy in the Age of Artificial Intelligence?
Medium · Machine Learning
🎓
Tutor Explanation
DeepCamp AI