- Podcasts
- CyberSecurity Summary
- Python for Scientists
About this episodeThis compilation of excerpts provides an introduction to Python for scientists, focusing on practical applications in numerical methods…
You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary
Get the Book now from Amazon:
https://www.amazon.com/Python-Scientists-John-M-Stewart/dp/1009014803?&linkCode=ll1&tag=cvthunderx-20&linkId=bf3b32f892911277db84a70fe42ab42d&language=en_US&ref_=as_li_ss_tl
Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Python for Scientists
Right, Yeah, like a formula one car. They can be incredibly fast because your code gets translated directly into efficient machine instructions by a compiler. Super powerful, But like driving enough one car, using them well takes a lot of skill and sometimes getting things working across different compilers can be tricky. Plus, you often need lots of external libraries for basic stuff.
Okay, imagine you need to read data from say, three different file types. You could try writing one super complicated function to handle all three, right, or the Pythonic way, the sort of encouraged style is to write three separate, clear functions. One function explicitly handles format A, another handles format B, and so on.
Immutability has its advantages. Sometimes you want to guarantee that a collection of values won't be accidentally changed. Also, because they're immutable, tuples can be used in places lists can't, like as keys and dictionaries another data structure. Any performance difference Sometimes ones maybe slightly less memory, but usually not the main reason you choose one. It's more about signaling intent. This group of values shouldn't change.
Lots? Indentation error is common for beginners. Python cares about spaces type error if you try to say, add a number in a string. Name error. If you use a variable you haven't defined value error if a function gets the right type but a bad value, like trying to convert zxyz to an integer. Zero division error is obvious. Index error if you try to access a list element that doesn't exist. File not founder if open can't find the file. Import error if it can't find a module you try to import.
Yes, that's what tri dot except blocks are for. You put the code that might cause an error inside the try dot block, and then you have one or more accept blocks. If an exception occurs in the triblock, Python looks for an accept block that matches the type of exception raised. If it finds one, it runs the code in that accept block instead of crashing.
Code essentially Yes, it contains functions, classes, variables. You use the import statement to bring that code into your program's namespace, like import math YEP. Then you access things inside it using the dot dot math dot pi math dot sinx. This dot mechanism is fundamental in Python for accessing attributes and methods of objects and modules.
Things like using four spaces for indentation, never tabs, limiting line length to make it easy to read around seventy nine or maybe a bit more characters, using meaningful variable names, using blank lines to group logical sections, consistent spacing around operators, adding comments where needed, but not over commenting obvious things.
Yeah, quite a tour. So just to recap, we've seen why Python is so big in science. It's accessible, flexible, explicit. We hit the basics data types like numbers, strings, lists, tuples, control flow with if and loops, building or usable code with functions, handling files and errors, even dipped into classes, and the vital role of modules like NUMPI.
