去投票

Learn Python in Only 30 Minutes (Beginner Tutorial) – YouTube Dictation Transcript & Vocabulary

欢迎来到 FluentDictation,您最佳的 YouTube 听写网站。使用我们的交互式逐字稿和跟读工具掌握此 C1 级别视频。《Learn Python in Only 30 Minutes (Beginner Tutorial)》已被拆分成易于练习的片段,适合听写和发音提升。阅读标注逐字稿,学习核心词汇,提升听力技能。 👉 开始听写练习

加入数千学习者,使用我们的 YouTube 听写工具提升英语听力与写作技能。

📺 Click to play this educational video. Best viewed with captions enabled for dictation practice.

交互式逐字稿与高亮

1.this video was brought to you by IND dentle IO learning python Made Simple how's it going everyone about 4 years ago I made a python crash course which recently blew up and I thought 4 years is a lot of time so it's time to make an updated course and this video will be useful if you are a beginner the only two requirements I have for this video is that you have python installed and you have your own code editor installed for this tutorial I'm going to be using pycharm it's completely free and you can find it on the jet brains website anyway let's get started the very first thing we're going to learn is how to run our very first script so here we're going to type in one of the most popular commands in any programming language and that is print hello world as you can see I'm using some quotation marks followed by some text and this is important when you want to insert text into Python and with print we can finally run this script by tapping on the Green Arrow and you'll see that inside the console we're going to get this as an output so we essentially told python to display this information and we can change this to anything we like we can even type in hello Bob and I'm using a shortcut which is command plus r to run my scripts if that doesn't work for you you're going to have to go to settings then go to the key map and type in run then inside here you'll find a section called run and debug and what you want to select is the Run feature and assign it your own shortcut anyway I'm going to be using that shortcut from now on so here we can change the text to whatever we like but it would be so much nicer if we could edit this in another place so what we're going to do next is create a variable and here we're going to call this variable name and the name is going to be set to Bob so now all we need to do is replace this section here with this variable and to do that I'm going to remove Bob I'm going to type in plus name plus exclamation mark and this is going to perform a string concatenation which means name is going to be added to hello and the exclamation mark will be added to name which means now when we run this we're going to get hello Bob and it would be nice if we had a space there but what's nice about this approach is that if we were to duplicate this line and we were to change this to James name will always stay up to date with the name that we defined here so now it's going to print hello James hello James without us having to type in James twice variables are great for reusability and it makes writing code so much easier anyway moving on I want to talk about the data types we have in Python because up until now we've been working with strings and strings are just text but we have many other data types so let's take a look at all of them so as I mentioned the first data type we encountered was a string which is just some text so for example here we can have some text which contains the value of Apple then a number is referred to as an integer in Python and that can be any whole number so 10 or - 10 that is an integer if you want to have a decimal this is referred to as a float and that's any decimal number so 10.5 or 10123 that's going to be considered a float then we have something called a Boolean which is either true or false so for example has money can be set to false with a capital f and again this only has two states false and true next we have something called a tuple and a tuple looks like this 2.5 comma 1.5 it's just a list likee structure which you cannot change after you create it so this contains two coordinates but you can even add more coordinates you can add I don't know 1.0 now it will contain three coordinates then we have a list and here we're going to create a variable called names and that's going to contain agneta bej Benny and anif Fred and to create a list you just need to use square brackets and this data is mutable which means we can remove elements and add elements unlike with tpls where the data is immutable which means once again once we create this we cannot change it next we have something that's called a set so here we're going to type in unique we're going to add 1 2 3 4 4 5 now the reason I called this unique is because a set cannot contain duplicates I mean you can insert duplicates but as soon as you print this to the console you'll notice that the duplicate of four will disappear so it's another list-like structure that cannot contain duplicates and finally we have something that's called a dictionary and a dictionary is a list-like structure that holds key value pairs for example here we might have a user called Bob with the value of one or the ID of one and James with the ID of two as you can see each element contains a key and a value so both of these are with each other and that's one element in the dictionary sometimes in Python you're going to be presented with one data type which you're going to want to convert into another data type for example sometimes you're going to try to scrape some information from the internet and what you're going to get back is let's say a number in the form of a string now the problem with this is that you can't use it as a regular integer with a regular integer you can do 10 + 10 for example and that will give us back 20 but if we were to do 10 plus number we're going to get an error because this type can only be added with other strings so in Python you can attempt to convert any data type into another data type by using the type Constructor and a type Constructor is literally just the type you want to turn it into followed by a pair of parentheses so here we're attempting to convert number into an integer and that's going to work perfectly fine because 100 is actually a number if we were to type in 10 it's going to give us a value error because 10 is not an integer it is text that represents the number 10 that only a human can understand so for this to work we need to add an actual number and as I mentioned earlier you just need to pass in the type you want to convert it to so it can be a string or a float or a set whatever data type you want to convert this variable into you just put the data type in front of it followed by parentheses and I mean you don't have to actually use a variable you can absolutely type it in directly here 1 2 3

2.456 and this will convert this string into a float now a very good practice for writing code is using type annotations this is something I want to teach you as early on as possible because it's going to save you a lot of trouble in the future but in Python it's not required you can type in something such as age is equal to the integer value of 10 but something you'll see me doing in all of my lessons is annotating it with the data type here I'm explicitly telling python that I want this to be of type integer and we might even have something called first name which will be of type string and that's going to equal Bob these are type annotations and they tell the code editor or the static type Checker what we're trying to do here python is going to ignore these which means that if we were to type in age of typ string equals 10 we're still going to be able to run this code with no problems but what you're going to notice is that the code editor is going to tell us that we messed up up so this is a tool used for the developer it tells us when we're making mistakes without this type annotation we can add 10 here we can add a string here we can add whatever we want and we're not going to get any errors because age can be literally anything but by providing the information that AG should be of type integer we will get some warnings that we're doing something silly here so that we'll have the chance to actually correct it so you're going to see me using type annotations everywhere it's not required but I prefer to do this because I think it's professional and it saves me a lot of effort anyway here I'm going to remove the first part of name because for the next example I want to teach you a very convenient concept called f strings because earlier I showed you that we could do something such as name plus name plus age plus age and we need to make sure that this is actually a string so what we have to do here is convert that to a string and with that when we run this we will get some nice output such as this one name of Bob age of 10 but this took a lot of effort and is not intuitive we want to be able to write this in a much more fluent way and luckily python provides us with the opportunity to use f strings in these situations which makes creating complex strings such as this one a lot easier so instead of doing all of that what we're going to do is print F and quotation marks and the F here stands for format and FST string is a formatted string also just to digress real quickly you're not required to only use single quotation marks that's just a simple preference of mine you can also use double quotation marks if you want that's up to you I just got accustomed to using single quotation marks because I think it looks cleaner but now with that we can type in name and using curly brackets we can insert variables directly so name and then age age this was just so convenient to type compared to the other string that we tried to concatenate and watch what happens when we run it it's going to run exactly the same way or I mean the output is going to be exactly the same so I recommend using FST strings whenever you can because this is just hard to keep track of you won't see many professional python developers using this moving on it's time we learn about functions and functions are used to make our code much more reusable just like with variables and to create a function in Python we use the def keyword which stands for or Define and immediately after that you add a function name so here we're going to create a function that takes two inputs or two arguments A and B and then it's going to add those together so a is going to be of type float and B is going to be of type float as well now using this Arrow we can tell python what we expect to return and here we expect to return a float because adding a to B will return a float then inside here we can return A+ B and with that being done we can print add 10 to 15 then we can duplicate this and say 15 to 30 and when we run that we're going to get the sum of both of those operations and what's great about this is that we can reuse this function anywhere in our script as many times as we like and it is as simple as that now you might be asking why didn't we just do 10 + 15 and 15 + 30 well this works perfectly fine but imagine we want to change something in the implementation of the function if we want to add some other code in here we're going to have to do it manually for each one of these but now let's go back to what we had earlier and inside the function what we're going to do is print that we are adding and I want to make this an FST string A+ B here we added a line of code and this change will be added to each function call as you can see now we have adding 10 + 15 and adding 15 + 30 so any change we bring to the function will be added to each function call which is very convenient but let's take a look at another example and this example we're going to create a function called greet which will take a name of typ string and a greeting of typ string and this will return none this time because we are only executing code so print the F string of greeting comma name and what's great about this is that we can type in greet followed by the name and the greeting and now when we run this we're going to get our simple greeting back but something else I want to show you is that we can also Define default values by using the equal sign Direct directly on the parameter and this will make it so we don't have to define a greeting each time we use the function which means the next time we can type in James and it won't require us to actually Supply a greeting as you can see it's going to say hi James because hi was the default for greeting and we can also do that with Bob once again the default will be used once again because we did not include greeting as an argument and I don't know if this was obvious or not but I'm just going to go over it anyway when you're creating a function you're not required to add any parameters is you can just say it's a function that executes some code such as hello then you can just call that function as many times as you want and it will execute that code each time and once again type annotations are optional they do not affect how your code is run but help the code editor with understanding what you're trying to do now that we understand how functions work let's move on to looping in Python and in Python we have two different kinds of Loops one is the for Loop and one is the while loop for Loops are used for finite looping while while Loops are used for infinite looping so let's take a look at a couple of examples to see the difference and how they actually work and first I'm going to start with the for Loop so to create a for Loop we use the for keyword and here we can add a variable name which in general is going to be set to I if you're just going through a range so here we're going to type in for I in range three print hello and range is going to create a r range of three numbers which means it's going to loop three times and once we run this you'll notice that it's going to say hello three times if we change this to five it's going to Loop through the range of five numbers and it's going to print hello five times and usually you'll see four Loops being used a lot with lists for example earlier we had this list of names with a for Loop we can say forame in names print hello and we'll change that to an FST string followed by the name so this is going to grab each name from that list and use it for each iteration which means now when we actually run this we're going to get hello anetta hello be hello Benny and hello anaf so as you can see for Loops are always used with a finite list of elements and it doesn't have to be one statement you can even add two statements you can say dot dot dot as you can see now we have two lines of code inside this for Loop and it will be executed four times because this list contains four elements anyway moving on we have the while loop as I mentioned earlier the while loop is infinite which means if we were to type in while true print hello this will be executed for as long as your computer exists as you can see there's no end to this condition true is true forever which means python will execute this code over and over again until the end of all things so right there I force stopped the script because there's no point in having that run forever usually with while Loops you're going to have some sort of condition such as while I is less than three and this is a condition which will turn false we actually need to create that above so I of type integer will equal zero now here we can print I and for each iteration we're going to type in I + 1 or i+ = 1 so I is going to increment one on each Loop meaning that one day this is going to become three which is not less than three and once this evaluates to false it's going to exit out of this while loop as you can see now when we run this we're going to have zero printed one printed two printed but as soon as I contains the value of three this statement or this expression evaluates to false which means the while loop will no longer continue with its Loops now up next we're going to talk about these comparison operations because there are quite a few that you're going to have to memorize and in this example I'm going to have two integers one called a and one called B and one will contain the value of one and the other one the value of two and I'm going to type these out real quick because they are the first check we're going to do is whether a is more than b or greater than b and we do that using the right arrow we can also check that a is greater than or equal to B so if a contains the value of B it's also going to evaluate to True right now if we were to run this we're going to get false for both of them because a is not greater than b but if we add two here the first expression is going to evaluate to false because a is not greater than B it's exactly the same as B but with greater than or equals to this will evaluate to true because a is equal to b anyway this also works in the opposite sense so you can check that a is less than b or whether a is less than or equal to B and that's going to work exactly the same way something else we can do is check whether a is equal to B whether these two contain the exact same value right now if we R to run this we're going to get false because 1 is not equal to two but if we insert two we will get true as a return and we can also do the opposite here we can check that a is not equal to B by using the exclamation mark and just like that we're going to get true as an output because a is not equal to B so these are the comparison operations that you should memorize because you'll be using them a lot throughout your programming career up next we're going to be talking about if L if and else which is used for control and flow logic now for this example we're going to simulate that we're getting some user input so here we'll type in user input of type string is equal to hello now if the user input is equal to hello we will print that the bot says hello L if the user input is equal to how are you we will say that the bot says good how about you and in every other situation we're going to use the else block so if what we type in doesn't match any of these conditions the else block is going to be executed and here we can print that the bot says so sorry I did not understand that and just like that we can try running this script and what we should get as an output is that the bot says hello otherwise if we change this to how are you the bot should respond good how about you and if we type in something random you'll see that the bot will not understand what we wrote so with if you can add any expression that you want to check for and this code will only be executed if this evaluates to True L if stands for else if which means if this doesn't pass it's going to try to check whether this will pass and if it does pass it will execute this code else will be executed in any other situation and what's important to note is that you can have as many l if statements as you want so you can also check that user input is equal to buy then the bot can say goodbye now when we actually enter buy as an input the bot's going to be able to respond with goodbye now if you want to see something really cool all we need to do here is type in inputs followed by U which is the prompt we want the user to see and add a while true Loop here then we need to indent all of this inside the while true Loop to make it a block of code and with those two simple changes we now have our very first chat bot we can type in hello the bot's going to respond if it finds that if we type in by it'll say goodbye if we say something random the bot's going to say sorry I did not understand that it was that simple to create a chat bot in in Python moving on it's time we talk about exceptions in Python what to do when you encounter one and how you can handle it properly because sometimes you're going to type in something weird such as print whatever that is and you're going to end up with an exception or an error such as a name error now in recent versions of python you're going to get very descriptive error messages which help you understand what you did wrong but of course it would be nice to learn how to handle these exceptions because the one that we just encountered was was caused by the developer but there are going to be some that might be caused by the user for example imagine we have two variables A and B and I'm going to be using the multiple assignment syntax which means we can type in 10 comma and the second variable and this will assign 10 to a and 15 to B on one line but for whatever reason Let's Pretend the user entered 15 now if we were to add a plus b we're going to end up with an exception because you cannot add a string to an integer it is an unsupported operant type int and string just do not go together but for whatever reason that's what the user input now if your user ever sees an exception message it's probably a bad thing and that can even lead them to uninstalling your app if it happens too even if they're in the wrong it's important to act as an adult when you are programming and to give the user a chance to fix their behavior for example instead of just printing a plus b what we're going to do is type in try which means we're going to try try this dangerous code and if it doesn't work we're going to accept exception as e and here we're going to print that something went wrong and we're going to insert e which is the error now the next time we run this we're not going to get an exception anymore we're going to get an error message instead which means we can actually run more code under this try and accept block here we can type in with the program as you can see when we run this it's going to be able to continue with the program even if we encounter exception without this the program is just going to crash and we're never going to reach the rest of the program so let's go back to what we had earlier here we can type in something else such as please enter a valid number so that the next time the user inserts the text of 15 and tries to add it to 10 the exception is going to tell them exactly what they need to do to fix it anyway that is the basic concept of handling an exception now what I did here is considered a bad practice because exception handles all of the exceptions when what we really wanted to do is handle the type error so as you can see we can be much more specific with our exceptions and here we can type in something such as please enter a number in the form of an integer or a float so now we're catching the correct error and giving them the correct message for that error which means that once they run the program and they add this silly input it's going to ask them to please enter the number in the form of an integer or a float which means now we can change this to 10.5 or actually to stay consistent we'll just type in 15 and it's going to work properly the next time they use that as an input and one last thing to note is that you can add multiple accept blocks so you can actually handle all the other errors just by adding another except block something else went wrong because sometimes certain operations are going to lead to multiple errors but once again I never recommend using exception as e unless it's really just a last resort because this exception will absorb all of the errors and one thing you need to learn in programming is that encountering errors and exceptions is not a bad thing when you are developing in fact you want to encounter as many as possible because this will lead to more consistent code when you're actually publishing your application it's going to help you understand everything that can actually go wrong and this approach just silently absorbs that error and makes it disappear so once again use this as a last resort now very quickly I want to talk about Imports in Python because sometimes you're going to want to import some external functionality into your script so that you can use it for example imagine you want to calculate the square root of a number now personally I'm no mathematician so I prefer to use pre-made functionality to perform that calculation and in Python we can import a module called math and what's good about this is that we can use a lot of its functionality for free just by importing it and coincident L it has a square root function so here we can calculate the square root of three using the square root function and once we run it we're going to get the square root of three we can also import math using an alias so for example import math as M now we can print M do square roots of four and it's going to work exactly the same way except we're using the Alias this time and finally if you really want to be specific with your Imports you can import from math the square root function and this time we just type in square root and five and it will work out of the box just by referring to the function name and just so you know with the third approach you can add as many as you want you can even add let's say tan which will return the tangent so we can type in tan of let's say two and that will work just fine just by referring to the name now to end this crash course we're going to be creating a simple project and this is actually one of my favorite projects to make and this is a chat bot a very simple chat bot so first we're going to create a bot name of typ string which is going to equal Bob then the first message is going to be a print statement that says hello I'm bot name how can I assist you today and once we see that message we will start our while true Loop which is an infinite Loop and the very first thing we want to do is take some user input which will be of type string and that's going to equal input with u and since this returns a string we're going to want to lower whatever the user enters and the reason we're doing that is because if the user types in hello with an uppercase H and we're trying to compare that to hello with a lowercase H this is going to return false because python is case and a capital h and a lowercase H are two different things now when you use the lower method on hello it turns all of the letters inside this string to lowercase which makes it much easier to compare the two anyway if user input is in the list of high hi or hello then we will print that the bot name says hi there how can I help you L if the user input is in by or CU we will print that the bot name says goodbye have a great day and as you can see here I'm checking that the user input is inside this list of strings which I find to be more convenient than checking for each one because it's nice to be able to understand multiple form of input but let's also add some functionality so L if use a input in Plus or add then let's make it so our bot can actually perform some mathematical operations print bot name says sure let's let's do some addition please enter two numbers and now comes the fun part what we need to do here is try to first get the first number which will be number one of type type float and that's going to equal the input of the first number and as you can see the code editor is telling us immediately that we got a string but we were expecting a float and thanks to this type annotation we can fix that by surrounding this with the float Constructor then we're going to duplicate this and say number two and type in second number and if that works we're going to print the F string with the bot name that says the sum is number one plus number two and if it doesn't work we're going to add the except block and the main exception we can encounter here is the user adding or inputting a letter or some sort of symbol that is not a number and that's going to give us a value error so here we can print that the bot name says oops that doesn't seem like a valid number try again then we're just going to get out of this accept block and go to the outermost layer where we have the if and we're going to add the else block and this is going to cover all of the cases that we did not cover Above So else print that the bot name says I'm sorry I don't understand that please try again and in only 20 lines of code we created our very first chatbot so now it's actually time to test that it works so here I'm going to run the script and I'm probably going to make that bigger so we can see and and I'm just going to type in high as I mentioned earlier the bot is going to be able to respond to that even if we have an uppercase H it's going to understand that we can type in goodbye and it doesn't understand that obviously because we did not code that we only coded buy and CU but if we type in buy it'll be able to respond to that but now let's try to add some numbers so we'll type in add We'll add 10 to 20 and the bot should give us the sum which is 30 if we type in something random the bot won't understand that and if we try to get the sum using the plus that's going to work too but let's pretend we add something that doesn't work such as oh the bot is going to tell us immediately that it doesn't seem like a valid number and instead of crashing our program it's going to tell us immediately which provides us with a much more smooth user experience anyway I'm just going to say bye and the bot will tell us goodbye have a great day so as you can see it was a very simple chatbot that had some very simple functionality but what's cool about this is that you can edit this as much as you like and you can add all sort of functionality and so on but yeah that just about sums up the basics of python there's still a lot more to learn but the best way to learn is to build apps so decide on something you want to build and start coding it as you try to build your app you're going to have to start googling to learn new things that's all part of being a programmer even after 5 years of programming I Google constantly although I recommend you start small otherwise it might be a bit overwhelming so search on how you can improve your chat Bots search on how you can scrape information from the internet but don't try to build Facebook from day one that's going to be incredibly overwhelming and it might even end with you giving up on programming because creating apps like Facebook isn't just one concept but hundreds of different concepts combined anyway I hope enjoyed this video do let me know in the comment section down below whether you have any other or whether a certain topic needed more but otherwise with all that being said as always thanks for watching and I'll see you in the next video

💡 Tap the highlighted words to see definitions and examples

关键词汇(CEFR C1)

associated

B1

To join in or form a league, union, or association.

Example:

"see each element contains a key and a value so both of these are associated with each other and that's one element"

frequently

B1

At frequent intervals.

Example:

"if it happens too frequently even if they're in the wrong it's important to act as an adult when you are programming"

questions

B1

A sentence, phrase or word which asks for information, reply or response; an interrogative.

Example:

"other questions or whether a certain topic needed more explanation but otherwise with all that being said as"

explanation

B2

The act or process of explaining.

Example:

"other questions or whether a certain topic needed more explanation but otherwise with all that being said as"

definition

B2

A statement of the meaning of a word or word group or a sign or symbol (dictionary definitions).

Example:

"definition or Define and immediately after that you add a function name so here we're going to create a function"

eventually

B1

In the end; at some later time, especially after a long time, a series of problems, struggles, delays or setbacks.

Example:

"eventually turn false we actually need to create that above so I of type integer will equal zero now here we can"

continueing

B2

A B2-level word commonly used in this context.

Example:

"continueing with the program as you can see when we run this it's going to be able to continue with the program even"

self-explanatory

B2

Obvious, having a nature that makes it clear or that explains itself.

Example:

"self-explanatory the first check we're going to do is whether a is more than b or greater than b and we do that using"

sensitive

B2

A person with a paranormal sensitivity to something that most cannot perceive.

Example:

"trying to compare that to hello with a lowercase H this is going to return false because python is case sensitive"

separately

B1

In a separate manner; not together; apart.

Example:

"separately because it's nice to be able to understand multiple form of input but"

想要更多 YouTube 听写练习?访问我们的 练习中心.

想要同时翻译多种语言?访问我们的Want to translate multiple languages at once? Visit our 多语言翻译器.

听写练习语法与发音技巧

1

Chunking

注意说话人在特定短语后的停顿,可帮助理解。

2

Linking

聆听连读现象,当单词连在一起时。

3

Intonation

关注音调变化,理解重点信息。

视频难度分析与数据

分类
basic
CEFR 等级
C1
时长
1844
总词数
6065
总句数
292
平均句长
21 词

可下载听写资料

Download Study Materials

Download these resources to practice offline. The transcript helps with reading comprehension, SRT subtitles work with video players, and the vocabulary list is perfect for flashcard apps.

Ready to practice?

Start your dictation practice now with this video and improve your English listening skills.