Carter Sande

Author
+ Follow
since Mar 08, 2020
Co-author, Hello World! Computer Programming for Kids and Other Beginners. The Third Edition adds Python 3, and a new chapter about how the Internet works!
San Francisco Bay Area
Cows and Likes
Cows
Total received
5
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carter Sande

Gibran,

Actually, Python programs are often a little less efficient than programs written in Java or C#. But if Python makes it easier for you to write those programs in the first place, it might be worth it for you! I wrote a little bit more about Python performance in another thread if you're interested.

You usually wouldn't use Python to write a mobile app. You'd use a programming language like Objective-C or Swift to make iOS apps, and Java or Kotlin to make Android apps. (There are also cross-platform frameworks that let you make apps for all kinds of phones using languages like C# or JavaScript. I don't think there's one for Python, but maybe I just haven't heard of it yet.) If you wanted to, you could use Python to write a server for your mobile app to talk to over the Internet.

That's one of the main things Python is used for in production systems: the "back-end" services that talk to databases and keep track of users' information. People also use Python to analyze data, automate tasks, and as a scripting language inside larger programs like 3D modeling tools.

- Carter
2 months ago
Shakthi,

Python often does perform slower than languages like Java. Part of that is because Python is dynamically typed like you mention, but part of it is just that the Python interpreter doesn't have fancy features like the "Just-In-Time compilation" that Java uses to run more quickly. (If you're interested, there's a project called PyPy that's trying to make a faster Python interpreter using JIT.)

If you're just starting out, the best advice I can give you is to try and keep your programs simple. The less work the computer has to do to run your program (calling less functions, making less objects, and so on), the faster it'll run.

Another way to help make your Python programs faster is to use functions written in other languages. C code, for example, runs more quickly but is a lot harder to write than Python code. So people have created modules like Pygame and NumPy that are mostly written in C, with an interface to use that fast C code from your Python program. A lot of Python's built-in functions are also written in C for that reason.

- Carter
2 months ago
We started working on the First Edition when I was 6 years old, and it came out when I was 9. Back then, I knew enough about programming to help write the book, but I wasn't really very good at it. So some of the example programs in the First Edition are a little goofy: the first version of Hangman I wrote used a horrible six-layer-deep nested if statement to keep track of which parts of the man to show on the screen. (We fixed it in the Second Edition, but all those printed copies of the First Edition will haunt me forever!)

You pronounce Sande like "sand", like on the beach. At least that's how I pronounce it.

- Carter
2 months ago
Zulfi,

I don't think your program is necessarily hanging up because there's a bug in it. (You did try the sorting program with a smaller list of numbers, right?) And like Travis said, you can make integers as big as you want in Python, so that's not the problem either.

Instead, I think your sorting program is just taking a really long time to run. The selection sort algorithm has quadratic time complexity, which is a fancy way of saying that if you make the list a thousand times longer, selection sort will take a MILLION times longer to sort it! As Tim mentioned, there are other sorting algorithms you can write that might be able to sort your list more quickly.

- Carter
2 months ago
Gibran,

There isn't really anything special about Python itself that makes it good for machine learning. Sure, Python looks nice and is easy to write code in, but there are a lot of programming languages like that.

The important thing is that lots of other people use Python for machine learning. That means that there are already a lot of ready-made Python modules, like NumPy, TensorFlow, and PyTorch, that you can download and use to do machine learning. It also means that if you ask your machine learning buddies for help writing a program, they'll probably know how to do it in Python. So it's probably mostly an accident of history that machine-learning people use Python and not Ruby or Perl.

There are also a lot of ready-made Python libraries for making web applications! Two of the most popular ones are called Django and Flask.

- Carter
2 months ago
Shakthi,

Some add-on modules for Python will include the exact argument and return types of their functions in the docs, just like you'd see in Java. The Python Standard Library documentation doesn't do this, but you can usually still figure it out by reading the description of the function and thinking about what makes sense for the function to return. Here's an example:

Python Standard Library documentation wrote:
random.betavariate(alpha, beta)
Beta distribution. Conditions on the parameters are alpha > 0 and beta > 0. Returned values range between 0 and 1.



The description says the function returns a value "between 0 and 1". So the function has to return a number, but it can't be an int because there are no ints between 0 and 1, so it has to be a float.

If it's hard to figure out the type from the documentation, you can also try opening up a Python console and running the function to see what it returns:



Also, keep in mind that in Python, it doesn't really matter what type a variable is so long as it has the methods and properties you need. (This is sometimes called "duck typing".) If you write x.endswith(".com") in your Python program, x could be a string, but it could also be some other class that has a method named endswith. So another strategy for dealing with types in Python is to not worry too much about them.

- Carter
2 months ago
Hello! I am very excited to answer all of your questions!
2 months ago
Hi Greg,

Once you've learned the basics of programming, what you do next really depends on what kind of programming you're interested in. You can learn to make games, or iPhone apps, or websites, or anything else you can think of!

I don't have any intermediate-level books to recommend off the top of my head, but we list a few websites to check out in Chapter 27 of the book. Here are a few more that I personally like:

- If you want to make web servers in Python: https://flask.palletsprojects.com/en/1.1.x/tutorial/#tutorial

- If you want to make Game Boy Advance games (I am probably the only one who wants to make Game Boy Advance games): https://www.coranac.com/tonc/text/toc.htm

- If you want to try fancy algorithm and math problems, like big tech companies ask in their job interviews: https://leetcode.com/

If anyone else has any intermediate programming resources they like, feel free to post them here!

- Carter
2 months ago