I’m so excited to be finally using Python.
I’ve been dabbling a teeny bit with Python in my spare time by watching tutorials on YouTube, but I’ve mostly been holding myself off from actually trying to learn it, else I’d get too interested and I’d push off CS50 and C11.
However, the stark contrast between the syntax and usability of C versus Python is immediately apparent.
C: printf(“hello, world\n”);
Py: print(“hello, world")
Compiling:
C: make programname.c
./programname
Py: code programname.py
python hello.py
Boom. Simple!
Admittedly, I don’t really have much to post about today, since we’re going over the most basic fundamentals of Python. However, having gotten some more into this particular course, the way in which programs can be simplified using pre-existing functions and libraries is astounding compared to C.
I’ve also been considering memory usage and efficiency a lot, as I know C is known for that, given its ability to manipulate bits and bytes from soup to nuts. Python, though, like other newer languages, uses a lot of preexisting functions and libraries like I just mentioned, and so the tradeoff for saving (apparently, multiple hours) time, generally speaking, is a performance drop in how information is ‘compiled.’ At least, until the program is run enough times so that the algorithm can be trained to more efficiently handle the program itself.
x—x
Divisive calculator test program:
x = int(input("x: "))
y = int(input("y:" ))
z = x / y
print(z)
x—x
Compare test program:
from cs50 import get_int
x = get_int("x: ")
y = get_int("y: ")
if x < y:
print("x is less than y")
elif x > y:
print("x is greater than y")
else:
print("x is equal to y")
This time, I’m using CS50 training wheels for the get_int function, and I’m also using elif to replace an else if function.
x—x
Sorry, really nothing interesting to write down today. CS50 is essentially lecturing about how the same concepts in C work in Python, and going over the syntax of different functions, elements and variables from Week 1 so far, so I don’t have much to show yet.
Thanks for reading,
Judson