Mike Driscoll Profile picture
Jun 12 5 tweets 2 min read
Even if you are a beginner, you have probably used #Python's built-in `print()` function.

But let's take a few minutes to talk about the humble `print()` function and see what you might have missed!

#python_builtins_by_driscollis

🧵🐍👇
The `print()` function takes the following arguments:

🐍 *objects - Stuff to print
🐍 sep=' ' - A string to separate object
🐍 end='\n' - A string to end on
🐍 file=sys.stdout - Where to write the data
🐍 flush=False - Whether or not to force flush the stream
Let's look at some examples of using Python's `print()` function:
You can use `print()` to write directly to a file by changing the `file` keyword argument to a file object.

This could be used kind of like logging, but Python's logging module is much better for that sort of thing.
Thanks for reading my mini-thread on Python's `print()` function.

See you next time! 🐍🔥

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Mike Driscoll

Mike Driscoll Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @driscollis

Jun 8
Let's talk about type hinting in #Python

🧵🐍👇
Type hinting is not enforced by Python. You can enforce it with outside packages, such as Mypy or with your Python IDE

I think @pycharm does a really good job of this, for example.
@pycharm Type hinting is most useful when you have a large team you are working with or with a large codebase.

Type hinting is also useful for introspection when creating Python packages
Read 7 tweets
Jun 5
#Python has had the concept of context managers for a loooong time!

Let's talk about context managers again!

🧵🐍👇
The `with` statement, which is the normal way for working with context managers, was added back in Python 2.5!

Here is a pretty common example of using a context manager:
The beauty of a context manager is that they allow you to do some setup and teardown automatically.

The downside is that is abstracted away and can sometimes make the code less obvious when debugging
Read 8 tweets
Jun 3
#Python added the `zoneinfo` module in 3.9, which provides a concrete time zone implementation to support the IANA time zone database.

You can learn more about it in PEP 615

python.org/dev/peps/pep-0…

#PythonStdLib 🐍🔥

🧵👇
Here is an example of using Python's `zoneinfo` module 🐍🔥
Here's another example of how you can from CDT to other timezones in the USA with #Python
Read 4 tweets
Jun 3
Did you know that #Python has a `slice()` function! 🐍

Let's learn more about that now!

🧵👇🐍
The `slice()` function returns a slice object representing the set of indices specified by `range(start, stop, step)`

Read more in the #Python docs here:

docs.python.org/3/library/func…
You can use the `slice()` function to created NAMED SLICES in #Python!

Here's an example:
Read 4 tweets
Jun 1
Hi 👋! I'm Mike!

I write about:

🐍 #Python
🕸️ Python Web Frameworks
💦 Python GUIs
🤖 Python & automation
📊 Python and data visualization
🐼 Python and data science
📚 Indie publishing
📖 Content creation
🐍 Python and PDFs
🔥 Python and Excel
🖼️ Python & Images

and more!
If you like to learn by reading tutorials, you should check out my website @mousevspython 🐭🐍

blog.pythonlibrary.org
@mousevspython If you are a visual learner, then you might enjoy my YouTube channel:

youtube.com/c/MouseVsPython
Read 5 tweets
May 11
Module number 3️⃣ on our #Python standard lib tour is `argparse`

The argparse module makes it easy to write user-friendly command-line interfaces.

#PythonStdLib 🐍🔥

🧵👇
Here is an example of creating an argument parser with no arguments.

Why would you do that? Well, to find out what `argparse` gives you out of the box 📦!

You can see here that `argparse` gives you some help text and prints out your provided description
A common coding pattern for argument parsing is to put the argument parsing code into its own function or method and then return the parsed args.

Here's an example:
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(