Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learn Python Programming
  • Table Of Contents Toc
  • Feedback & Rating feedback
Learn Python Programming

Learn Python Programming - Fourth Edition

By : Fabrizio Romano, Heinrich Kruger
3.5 (2)
close
close
Learn Python Programming

Learn Python Programming

3.5 (2)
By: Fabrizio Romano, Heinrich Kruger

Overview of this book

Learn Python Programming, Fourth Edition, provides a comprehensive, up-to-date introduction to Python programming, covering fundamental concepts and practical applications. This edition has been meticulously updated to include the latest features from Python versions 3.9 to 3.12, new chapters on type hinting and CLI applications, and updated examples reflecting modern Python web development practices. This Python book empowers you to take ownership of writing your software and become independent in fetching the resources you need. By the end of this book, you will have a clear idea of where to go and how to build on what you have learned from the book. Through examples, the book explores a wide range of applications and concludes by building real-world Python projects based on the concepts you have learned. This Python book offers a clear and practical guide to mastering Python and applying it effectively in various domains, such as data science, web development, and automation.
Table of Contents (20 chapters)
close
close
18
Other Books You May Enjoy
19
Index

One final example

Before we finish off this chapter, let us go through one last example. We could write a function to generate a list of prime numbers up to a limit; we have already seen the code for this in Chapter 3, Conditionals and Iteration, so let us make it a function and, to keep it interesting, let us optimize it a bit.

First of all, we do not need to divide by all the numbers from 2 to N-1 to decide whether a number, N, is prime. We can stop at √N (the square root of N). Moreover, we do not need to test the division for all the numbers from 2 to √N, as we can just use the primes in that range. We leave it up to you to figure out the math for why this works, if you are interested.

Let us see how the code changes:

# primes.py
from math import sqrt, ceil
def get_primes(n):
    """Calculate a list of primes up to n (included)."""
    primelist = []
    for candidate in range(2, n + 1):
        is_prime = True
        root = ceil(sqrt...
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learn Python Programming
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon