YouTube2Text

IQB Prep Notebook A - Python Basics — Transcript

by PyBMB · 4,297 words · 593 segments · language en · Watch on YouTube

Full transcript

  1. 0:07Hello, my name is Paul Craig. I'm a
  2. 0:09professor at the Rochester Institute of
  3. 0:11Technology and I'll be one of your
  4. 0:13leaders for the course Python for Chem
  5. 0:16Informatics Driven Molecular Docking,
  6. 0:19which will be held on May 1st, uh, 2025
  7. 0:22from 1 to 5:00 p.m.
  8. 0:24virtually. And you'll receive links for
  9. 0:27that, uh, through other sources. But
  10. 0:29right now, I'm preparing a series of
  11. 0:32five videos to help you prepare for this
  12. 0:36crash course. And these videos are
  13. 0:38designed primarily for people who are
  14. 0:40quite new to Python programming. So if
  15. 0:43you're experienced with Python, you may
  16. 0:45not find these so
  17. 0:47useful. And our course Python for
  18. 0:50chemiratics driven molecular docking is
  19. 0:53designed. So we'll start off, it's a
  20. 0:554-hour course. We'll start off with one
  21. 0:57hour of introductory material where
  22. 0:59you'll learn just a little bit of basic
  23. 1:01Python
  24. 1:03um some of the libraries that we use uh
  25. 1:06particularly RDKit pandas and seabour
  26. 1:10and and how to get ready to participate
  27. 1:12in the workshop. This will be followed
  28. 1:15by an hour with Pat Walters. And in that
  29. 1:17hour, he'll teach you how to use Chem
  30. 1:19Informatics tools to extract structures
  31. 1:23from a place called Binding
  32. 1:25DB. And we'll be looking at some
  33. 1:28material from a patent and compounds
  34. 1:31from a patent. After that, Levi Nen is
  35. 1:34going
  36. 1:36to teach you how to prepare the proteins
  37. 1:39and the small molecules for docking. And
  38. 1:42finally, Jessica Nash is going to take
  39. 1:43you through a docking
  40. 1:45process. This is the first of five
  41. 1:47preparatory videos. And in this video,
  42. 1:50we'll be looking at just some
  43. 1:52introductory material to help us get
  44. 1:53started. So, I'm going to switch over to
  45. 1:55that screen or to
  46. 1:58um to another screen right now.
  47. 2:10So at this point you should be seeing
  48. 2:12the screen about uh that shows the
  49. 2:14molecular sciences software institute
  50. 2:16logo and this is the first of five
  51. 2:19videos I'll be preparing. These
  52. 2:21notebooks will be available to you and
  53. 2:23we'll get these to you uh through a
  54. 2:25separate
  55. 2:27document and you can follow along and
  56. 2:30use the links to those notebooks to
  57. 2:32actually work these problems yourself.
  58. 2:34So, in each of these uh in each of our
  59. 2:37notebooks, we're going to have some kind
  60. 2:38of an overview to explain some of the
  61. 2:40questions we want to ask and the
  62. 2:42objectives we hope to achieve by the end
  63. 2:44of that video. So, in this one, what is
  64. 2:47the Python programming language and what
  65. 2:49is it used for? What is the basic syntax
  66. 2:52of the Python programming language? What
  67. 2:54is a Python list? What is a Python
  68. 2:58dictionary? And what is a for
  69. 3:00loop? And notice we've got four written
  70. 3:03in a slightly different font to just
  71. 3:04make it stand out some. And in fact, it
  72. 3:06will show up in a different font when we
  73. 3:08use it in Python
  74. 3:10coding. The objectives here are to learn
  75. 3:12to assign values to
  76. 3:14variables. Learn to use the print
  77. 3:16function to check how the code is
  78. 3:17working. We'll use a for loop to perform
  79. 3:20the same action on all the items in a
  80. 3:22list. And then we'll use the append
  81. 3:24function to append to create new lists
  82. 3:26in for loops. So what is Python? Well,
  83. 3:30Python is a programming language and was
  84. 3:33first developed in 1991 and has been
  85. 3:36used a lot. It's uh considered quite
  86. 3:39intuitive. It's the one I'm um most used
  87. 3:42to working with. It's also very
  88. 3:44versatile and it's very good at working
  89. 3:45with biological and chem chemical data.
  90. 3:48A lot of the artificial intelligence
  91. 3:50that's being done these days is being
  92. 3:51done using Python as a starting point.
  93. 3:54So these initial lessons will be run uh
  94. 3:57you will run Python interactively
  95. 3:59through a Python interpreter and the
  96. 4:01environment we use will actually be
  97. 4:02Google Collab. And so in Google Collab
  98. 4:06uh we launch that by just entering
  99. 4:09collab.resarch.google.com on a browser.
  100. 4:11Chrome works the best and go from there.
  101. 4:14And we're going to start off this
  102. 4:16exercise just by introducing a few
  103. 4:18things. Now what I want you to notice
  104. 4:20here, this is uh the top cells here
  105. 4:24where all this text is written. These
  106. 4:26are written in what's called markdown.
  107. 4:27So if I double click on this, you see a
  108. 4:30bunch of text that looks like um kind of
  109. 4:33a fixed font uh text on the left hand
  110. 4:36side and what it looks like on the right
  111. 4:37hand side. And if I hit shift return, I
  112. 4:41actually see the original text. So I can
  113. 4:43go in and modify this text to explain
  114. 4:45what's going on. So we have what are
  115. 4:46called markdown cells. That's what I
  116. 4:48just showed you. Then we have coding
  117. 4:50cells. So this is our first coding cell.
  118. 4:53In this coding cell, I want you to go
  119. 4:55through and just use a and use it as a
  120. 4:58calculator. So if we type in 3 +
  121. 5:027 then
  122. 5:07uh and then if I hit the the what I
  123. 5:09guess I'll call this the play button
  124. 5:11over here or the run the run button. If
  125. 5:13I hit that, typically it takes a few
  126. 5:15seconds for the first run uh run button
  127. 5:17in a in a collab notebook to run and
  128. 5:19then it gives us an answer. So it
  129. 5:21calculates a value of 10. All right. So
  130. 5:23we can use this as a calculator, but we
  131. 5:25want to do more than that. And in fact,
  132. 5:27this number is only useful to us if we
  133. 5:30assign it to a variable. And so the way
  134. 5:32we work with variables in Python is we
  135. 5:36have a variable name and we say variable
  136. 5:38name equals variable value. Okay? And
  137. 5:41even looking at this now, I can see that
  138. 5:43variable value is misspelled. But
  139. 5:45anyway, uh and we just assign a value to
  140. 5:49a variable. That value could be a
  141. 5:50number. It could be a series of of
  142. 5:53letters in what we call a string. And so
  143. 5:56in the next cell, we're just going to do
  144. 5:58a little physical chemistry here. So
  145. 6:00delta H or enthalpy is equal to a value
  146. 6:02of
  147. 6:04-541.5. And notice I have a pound sign
  148. 6:07here followed by KJ per mole. That pound
  149. 6:10sign tells Python that this is a
  150. 6:12comment. So we can't actually include
  151. 6:14the units in the calculation in Python
  152. 6:17uh with the variable but we can we can
  153. 6:19indicate what they are here. Delta S is
  154. 6:21entropy is equal to 10.4 and that's also
  155. 6:24KJ per per mole Kelvin and that's once
  156. 6:28again a comment. Finally the temperature
  157. 6:30298 is again in Kelvin and then we say
  158. 6:34delta G is equal to delta H minus temp
  159. 6:37delta S. And so if I hit the run button,
  160. 6:40it does that calculation. However, we
  161. 6:43don't know what the answer is because we
  162. 6:44haven't told it to tell us what the
  163. 6:46answer is. So the first function I'm
  164. 6:48going to introduce you to is the print
  165. 6:50function. And notice I have a a a
  166. 6:52comment here to do. And the thing we
  167. 6:54need to do in this cell is enter the
  168. 6:56name of the variable whose value you
  169. 6:57want to know. So we want to know the
  170. 6:59value of delta G. So I just type in
  171. 7:01delta G and I hit the run button and it
  172. 7:05gives us a value there of -3
  173. 7:093,640.7 and a bunch of digits. All
  174. 7:11right, so that's our understanding. And
  175. 7:14so to check our understanding in the
  176. 7:16next cell, we're going to actually look
  177. 7:19at calculating the pressure of one mole
  178. 7:21of nitrogen gas in a sealed container
  179. 7:23with a volume of 10 L at
  180. 7:26273.15 Kelvin using the ideal gas law.
  181. 7:29and we'll use the R value of
  182. 7:320.0821 liter atmospheres per mole Kelvin
  183. 7:36for the gas constant. So what I'm going
  184. 7:38to do here is I'm going to actually
  185. 7:40declare some variables. So I'm going to
  186. 7:42say uh the first thing is moles. So we
  187. 7:44say n
  188. 7:46equals 1 and then in comments I don't
  189. 7:49want that period sign. So I'm going to
  190. 7:51get rid of that. And I'm going make a
  191. 7:52comment. I'm going to say moles of
  192. 7:58nitrogen gas. All right. So now I'm
  193. 8:01going to go to the next
  194. 8:03line. Now this one's a little indented.
  195. 8:06I don't want it
  196. 8:07indented there. So in the next line I'm
  197. 8:10going to say that the volume V equals
  198. 8:1410. And then I'll put a comment
  199. 8:18lers. And notice what Google's what
  200. 8:22Collab's doing now is it's automatically
  201. 8:24filling the other portions in. So if I
  202. 8:25have, you can see it says T=
  203. 8:28273.15 with a comment of K and then the
  204. 8:31R value there with a comment of the
  205. 8:32units. If I just hit tab, those are
  206. 8:35accepted. All right. So now I'm going to
  207. 8:37write an equation to solve for pressure.
  208. 8:40So my equation is going to be remember
  209. 8:42the ideal gas law PV= NRT. So, I'm going
  210. 8:44to have n
  211. 8:46* r * t over v. And notice that Google
  212. 8:52Collab keeps making suggestions. So, now
  213. 8:55I'm going to hit the run button. And we
  214. 8:59get a value then for the
  215. 9:03pressure. So, we use a lot of functions
  216. 9:06in Google Collab or or in in these
  217. 9:08notebooks. And so the tip typical way a
  218. 9:11function is used is there's a name of
  219. 9:13the function and then in parentheses
  220. 9:15after the function there's one or more
  221. 9:17arguments. Now notice there's a
  222. 9:19parenthesis here. Parenthesis functions
  223. 9:22are normally followed by parenthesis.
  224. 9:23We'll see some other we'll see square
  225. 9:25brackets and curly brackets later as we
  226. 9:27go through uh this material. All right.
  227. 9:31So let's take a look at how this
  228. 9:33function works. So we're going to say
  229. 9:35print delta G and then we're going to
  230. 9:38multiply delta G times a th00and and
  231. 9:40print delta G
  232. 9:41again. So when we do that we can see
  233. 9:44that the value of delta G doesn't
  234. 9:46change. So even though we multiply delta
  235. 9:48G by a th00and it did not change. All
  236. 9:51right. Now I'm going to go into the next
  237. 9:54cell. I'm going to say print delta G.
  238. 9:55I'm going to say delta G equals delta G
  239. 9:58* 1. Now this is not something you would
  240. 10:00ever do in a math class but in a in the
  241. 10:04Python programming language we can
  242. 10:06change the the value of a variable even
  243. 10:08using the same name of the same
  244. 10:10variable. So what's going to happen is
  245. 10:11the new value that's going to be
  246. 10:12assigned here is going to be delta G *
  247. 10:141000. Now I want to show you something
  248. 10:17here. If I click on this X and the curly
  249. 10:20brackets on the side of the collab
  250. 10:22screen, it brings up a list of variables
  251. 10:24here and it tells me what those
  252. 10:26variables are and it tells me the type
  253. 10:28of those variables. So we have all these
  254. 10:30variables that are either floats which
  255. 10:32mean decimal numbers or integers. All
  256. 10:35right, so those are the variables we're
  257. 10:36showing and if I if I squeeze this over
  258. 10:39a little further, we can see the values.
  259. 10:40So we see the value of delta G here is
  260. 10:42-3,640.7.
  261. 10:46All right. So, I'm going to execute this
  262. 10:48cell and look what happens to the value
  263. 10:49for delta G over
  264. 10:52here. It changed. It went up by a
  265. 10:54thousand. All right. So, this is the way
  266. 10:57we can track our
  267. 11:00variables. And well, I want to do some
  268. 11:03more with delta G. But before I do
  269. 11:06that, what I'm going to do is I'm going
  270. 11:08to reset delta G to the original value.
  271. 11:10So, I'm just using the equation we had
  272. 11:12above. So this equation we had above
  273. 11:14uses the value of delta h
  274. 11:17temperature and delta s that we had
  275. 11:19above. So when I hit run here, it's
  276. 11:21going to calculate delta g again. It'll
  277. 11:23go back to the original value. Then
  278. 11:25we're going to create a unit a variable
  279. 11:27called delta g jewels. So this is in
  280. 11:30going to be jewels where the original
  281. 11:31delta g is in kilogjles. Then we'll
  282. 11:33print delta g. Then we'll print delta g
  283. 11:37jewels. And after I do this, let's take
  284. 11:39a look at our variables list.
  285. 11:42So very quickly we got those values
  286. 11:44there. If we go to our variables list,
  287. 11:46we can see that delta G is
  288. 11:50-3,640.7 and delta
  289. 11:52G_JU is
  290. 11:56-3,640,700. All right. And so I'm going
  291. 11:58to close that list just to give us some
  292. 12:00more space on the screen, but you can
  293. 12:02always check your variables and find out
  294. 12:03what they
  295. 12:05are. Now when we work with numbers uh
  296. 12:09and we already saw a little bit of this
  297. 12:11but if we want to find out what kind of
  298. 12:14what type of uh value is assigned to a
  299. 12:17variable we can type the name of the
  300. 12:18variable we use the type function and
  301. 12:20then in the parenthesis we put the name
  302. 12:23of the variable. So the type for delta G
  303. 12:25if I hit run it tells me it's a float.
  304. 12:29Now if I go back and I say well what's
  305. 12:30the type for
  306. 12:32volume? All right, if I run that one,
  307. 12:35tells me it's an integer or an int.
  308. 12:37Okay, remember that we just assigned a
  309. 12:39value v equals 10, I think, or something
  310. 12:42like that earlier. So, it just assumed
  311. 12:44it's a an integer unless you put a
  312. 12:46decimal point after it or it has some
  313. 12:47decimal
  314. 12:48values. Now, it's also possible to
  315. 12:51change the data type for a variable. So,
  316. 12:53we could say delta G string is equal to
  317. 12:56string delta G. And if we go in here,
  318. 12:59now our to-do here is just enter the
  319. 13:01name of the variable. We want to know
  320. 13:02what the type is. So delta G string. Now
  321. 13:05notice when I start typing in this in
  322. 13:07Google Collabs becomes helpful again.
  323. 13:09And so that's the variable I want when I
  324. 13:12run it. Now that's a string. So there's
  325. 13:15actually um it looks like a number. So
  326. 13:18if I if I print the
  327. 13:20value. So if I say
  328. 13:24print delta G string.
  329. 13:31Okay, it looks like a number, but it's a
  330. 13:33string. Okay, and we can't use it in a
  331. 13:36calculation because it's not a number at
  332. 13:38this point. All right, then it's also
  333. 13:40possible to assign a a series of
  334. 13:44characters to a string. So, we put these
  335. 13:46characters in a quote. We say string
  336. 13:48variable equals and with the quotes when
  337. 13:50we put the quotes there, Python knows
  338. 13:53that this is a string. So, when I run
  339. 13:54this
  340. 13:56cell, we see that the class for this
  341. 13:59variable is a string.
  342. 14:02One of the things we commonly use in
  343. 14:05Python is a list. And so we have a list
  344. 14:09here,
  345. 14:10energy_kal, and that's equal to, notice
  346. 14:13we have square brackets here with four
  347. 14:15numbers separated by commas. Okay. Now I
  348. 14:18can determine the length of this list. I
  349. 14:21just type I go here in energy length.
  350. 14:23energy_length is equal to len and then
  351. 14:26in parenthesis need to enter a variable
  352. 14:28whose length we want to know. All right.
  353. 14:31And the variable we want to know. I'll
  354. 14:32just type in e and Google collab starts
  355. 14:35getting helpful again. I'm going to say
  356. 14:37energy kcal. All right. And then I want
  357. 14:41to find out the list of this. So I just
  358. 14:43have a print statement print. And I have
  359. 14:45in quotes single quotes or double
  360. 14:47quotes. It doesn't matter as long as
  361. 14:48they match. The length of this list is
  362. 14:51followed by a comma followed by the
  363. 14:52variable that contains the number that
  364. 14:54we're interested in. So I I can hit the
  365. 14:57run button. I can also hit shift return
  366. 15:00to get the answer. So the length of this
  367. 15:01list is four. There are four elements in
  368. 15:03this
  369. 15:06list. So we can address the list one
  370. 15:09element at a time. And
  371. 15:13so this is where we learn about counting
  372. 15:15in Python. In Python, numbering starts
  373. 15:19at zero. So if I want to see that first
  374. 15:21element, that -3.4, I put in a zero here
  375. 15:26and I run that cell and I get
  376. 15:2913.4 or negative 13.4. And if I go back
  377. 15:34and I say let's look at number
  378. 15:36one, I get the value
  379. 15:39-2.7. Okay. And in fact each of the
  380. 15:44elements in a list can be used in a
  381. 15:45calculation. So I can say energy in
  382. 15:48kilogjles is equal to energy in kiloals
  383. 15:51times
  384. 15:534.184. All right. Now notice it's energy
  385. 15:56kiloal square bracket 1. So this is
  386. 15:59actually the second element in the list
  387. 16:01which is
  388. 16:02-2.7. So when I run this cell I get the
  389. 16:06value for that second element in the
  390. 16:08list in in kilogjles instead of kilo
  391. 16:12calories. Now another a nice thing about
  392. 16:14list that you can do in Python is you
  393. 16:16can do slices. All right. So a slice the
  394. 16:21way it works is the slice starts with
  395. 16:23the first number you put in the square
  396. 16:24bracket. You put a colon and then you
  397. 16:26put the last number and it goes up to
  398. 16:29but does not include that last number.
  399. 16:31So short list is energy kcals starting
  400. 16:34from element zero it will include
  401. 16:37element one but not element
  402. 16:39two. So I've done that and so in order
  403. 16:42to see what's there I'm going to say
  404. 16:43print short
  405. 16:45list. When I print short list I can see
  406. 16:48that I have the first two elements of
  407. 16:49that of the original list of energy
  408. 16:52kal. All right. Now it's possible to go
  409. 16:55through and I won't actually execute
  410. 16:57these. I'm just going to describe what
  411. 16:58happens if I say slice 1 equals energy
  412. 17:02kcal 1 colon. That means it starts with
  413. 17:05the first element and goes to the end of
  414. 17:06the list. All right? And slice 2 equals
  415. 17:10energy kcal and it starts with a colon
  416. 17:13and goes to three. That means it starts
  417. 17:15with the the first element in the list.
  418. 17:18Maybe I should say the zeroth element in
  419. 17:19the list and goes up to but does not
  420. 17:21include that element in in position
  421. 17:24three. So slice one is actually going to
  422. 17:27give us uh the first element through the
  423. 17:30end of the list. All right. So it starts
  424. 17:32with -2.7. It skips the the zeroith
  425. 17:35element. And slice two starts with the
  426. 17:39the zeroith element on the list and goes
  427. 17:41up to but does not include element
  428. 17:46three. Now we're going to move from
  429. 17:48lists to for loops. For loops are a way
  430. 17:52that we can repeat an action many times.
  431. 17:55Okay. So if we have a for loop and we
  432. 17:58type this in a coding cell, we type in
  433. 18:00for variable in list, put a colon. When
  434. 18:03you hit return after putting that colon
  435. 18:05in, Python will automatically indent the
  436. 18:07next line and then it has a bunch of you
  437. 18:10can put in as many commands as you want
  438. 18:12here to have it execute those commands
  439. 18:14on that variable from that list. All
  440. 18:17right. And
  441. 18:21We can do that. For example, we can say
  442. 18:24for number in energy kcal. And to be
  443. 18:28honest, it doesn't really matter what we
  444. 18:29call this. Just that number is how we're
  445. 18:32going to refer to each individual
  446. 18:34element as we go through the loop. So
  447. 18:36the first time through the loop, it's
  448. 18:37going to take the zeroith element and do
  449. 18:38the calculation. The next time we'll
  450. 18:40take element one, then element two, then
  451. 18:42element three. All right. So if I hit
  452. 18:44the run button, we get a list of four
  453. 18:47outputs. So these are the four outputs
  454. 18:49where we've converted the number from
  455. 18:52kilo calories to kilogjles. So we went
  456. 18:54through that list and did that. Now that
  457. 18:56seems like we're getting somewhere. All
  458. 18:57right. So one of the things we like to
  459. 19:00do then is we want to have a list where
  460. 19:02we can append any new element that
  461. 19:04happens that's generated in a loop to
  462. 19:06the end of an existing list. So if I go
  463. 19:08back here, I'm going to do the same
  464. 19:10exact thing only this time to say
  465. 19:14energy_kcal.append in parenthesis kj.
  466. 19:16So, we're going to append that to a
  467. 19:18list. All right. So, I hit the the run
  468. 19:20button here. When I do that, I get an
  469. 19:23error. And the error says, well, energy
  470. 19:26kcal is not defined. All right. So, so
  471. 19:29the list we wanted to add to isn't
  472. 19:32available. So, what we need to do is we
  473. 19:34actually need to create that list. So,
  474. 19:37what we do here is when we declare a
  475. 19:39list variable, if we want to create an
  476. 19:42empty list, we just put an open and a
  477. 19:44close square bracket. All right. And so
  478. 19:47we've declared an empty list. We could
  479. 19:48put some numbers in there, but we we
  480. 19:50just want to have the numbers that we're
  481. 19:52adding from this calculation. So what
  482. 19:54we'll do in this for loop is we're going
  483. 19:56to go through each of the elements in
  484. 19:58energy kcal. And for each of those
  485. 20:02numbers, we're going to determine a
  486. 20:04value in kilogjles by multiplying that
  487. 20:06number by
  488. 20:084.184. And then once we've done that,
  489. 20:10we're going to append the value for in
  490. 20:13kilogjles. We're going to append that
  491. 20:15value to this list. And then we're going
  492. 20:16to print the
  493. 20:18list. And so you can see now we have a
  494. 20:21list of those four numbers and it's a
  495. 20:23it's in square brackets that tells us
  496. 20:25it's a list. Another thing that we do in
  497. 20:30uh very often in in writing code is we
  498. 20:32make choices using logic statement.
  499. 20:35Okay. So in this cell we're going to
  500. 20:39have a new list. negative energy kj
  501. 20:42jewles KJ is equal to an empty list. So
  502. 20:45we're going to say for number in this
  503. 20:48list we have energy KJ. For numbers in
  504. 20:52this list one at a time we're going to
  505. 20:54go through and say if that number is
  506. 20:56less than zero then we have a colon we
  507. 20:58type after that and it automatically
  508. 21:01gets indented again. And what we're
  509. 21:03going to do is we're going to append
  510. 21:04that number to our negative energy KJ
  511. 21:08list. and then we'll print that list. So
  512. 21:11when we do that, you can see we've got
  513. 21:13two elements in that list. And this is
  514. 21:16this is correct because we had two
  515. 21:18negative numbers in the list
  516. 21:20here. You may be looking at this and
  517. 21:22wondering why are there so many digits
  518. 21:24after the decimal point. There are ways
  519. 21:26to control that and we'll do that in
  520. 21:28future efforts. All right. Now in
  521. 21:32addition to the greater than sign, we
  522. 21:33can use and a comparison operator equals
  523. 21:37equals. So, our two numbers equal to
  524. 21:38each other. Not equal to each other is a
  525. 21:41is an exclamation point. Equals. Greater
  526. 21:43than is a greater than sign. Less than
  527. 21:45is a less than sign. Greater than or
  528. 21:48equal to is simply greater than sign
  529. 21:49followed by an equal sign right next to
  530. 21:51each other. No spaces. Less than or
  531. 21:53equal to is a less than followed by an
  532. 21:55equal sign with no
  533. 21:57spaces.
  534. 21:59So, we can we've already done this and
  535. 22:03we're going to modify this one slightly
  536. 22:04and say negative numbers. And we're
  537. 22:06going to say for number in energy KJ if
  538. 22:09the number is less than zero or the
  539. 22:11number is equal to zero then we're gonna
  540. 22:14we're going to append that number to the
  541. 22:15list and print it. Now that list didn't
  542. 22:18have any zeros in it so it doesn't show
  543. 22:20up. But what happens we can also have an
  544. 22:22alternative. So we can say we're going
  545. 22:25to create two lists this time. Negative
  546. 22:26numbers and positive numbers. And so for
  547. 22:30for a number in that list energy KJ and
  548. 22:33notice when I hover over this collab
  549. 22:36tells me that it's a list and that there
  550. 22:37are four items in the list. All right.
  551. 22:40So our first statement is if the number
  552. 22:42is less than zero or the number is equal
  553. 22:44to zero we're going to add that number
  554. 22:46to the list negative
  555. 22:48numbers. Or else if it's if it doesn't
  556. 22:51meet this first comparison then it's
  557. 22:53going to add that list that number to
  558. 22:55the list of positive numbers. And if we
  559. 22:57do that and run this cell, we can see
  560. 22:59that we have the two negative numbers
  561. 23:01show up in our list called negative
  562. 23:03numbers. And the two positive numbers
  563. 23:05show up in our list called positive
  564. 23:06numbers. Now, notice what what I've done
  565. 23:08here. I've got print and then in quotes
  566. 23:11negative numbers colon quote and then a
  567. 23:14comma and then the negative numbers. All
  568. 23:16right? So, I can print a string along
  569. 23:19with uh the values for a variable to
  570. 23:21make the information clearer.
  571. 23:24Now, it's also possible to use what are
  572. 23:26called formatted strings. Okay? And
  573. 23:29formatted strings start with an F. So,
  574. 23:33we have an F followed by a quote sign
  575. 23:36and then anything inside that quote, you
  576. 23:38can put any letter you want to in there.
  577. 23:40It will be treated as a string. If you
  578. 23:42want to put in a variable value, you put
  579. 23:44it inside curly brackets. Okay? So here
  580. 23:48we can say f quote the positive numbers
  581. 23:51are and then curly bracket open positive
  582. 23:53underscore numbers curly bracket closed
  583. 23:56period and the the quote is closed. Now
  584. 23:58I'm going to say print my string. So I'm
  585. 24:00just printing what's in this variable in
  586. 24:03this uh in this
  587. 24:05cell and I you can see that the positive
  588. 24:08numbers are and it shows those two
  589. 24:10positive numbers and it also indicates
  590. 24:12that that's still a list with the square
  591. 24:14brackets. So, that's the end of the
  592. 24:17first preparatory video. I hope you
  593. 24:20found this helpful.

About this transcript

This page contains the full transcript of IQB Prep Notebook A - Python Basics by PyBMB, generated from the public captions YouTube serves with the video. The transcript has 4,297 words across 593 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.