r/Python • u/dimakiss • Jun 10 '20
r/Python • u/[deleted] • Nov 17 '19
This is one of the most interesting outputs of the particle simulation :)
r/Python • u/deepkrg17 • Oct 27 '23
Tutorial You should know these f-string tricks
F-strings are faster than the other string formatting methods and are easier to read and use. Here are some tricks you may not have known.
1. Number formatting :
You can do various formatting with numbers.
>>> number = 150
>>> # decimal places to n -> .nf
>>> print(f"number: {number:.2f}")
number: 150.00
>>> # hex conversion
>>> print(f"hex: {number:#0x}")
hex: 0x96
>>> # binary conversion
>>> print(f"binary: {number:b}")
binary: 10010110
>>> # octal conversion
>>> print(f"octal: {number:o}")
octal: 226
>>> # scientific notation
>>> print(f"scientific: {number:e}")
scientific: 1.500000e+02
>>> # total number of characters
>>> print(f"Number: {number:09}")
Number: 000000150
>>> ratio = 1 / 2
>>> # percentage with 2 decimal places
>>> print(f"percentage = {ratio:.2%}")
percentage = 50.00%2. Stop writing print(fβvar = {var}β)
This is the debug feature with f-strings. This is known as self-documenting expression released in Python 3.8 .
>>> a, b = 5, 15
>>> print(f"a = {a}") # Doing this ?
a = 5
>>> # Do this instead.
>>> print(f"{a = }")
a = 5
>>> # Arithmatic operations
>>> print(f"{a + b = }")
a + b = 20
>>> # with formatting
>>> print(f"{a + b = :.2f}")
a + b = 20.003. Date formatting
You can do strftime() formattings from f-string.
>>> import datetime
>>> today = datetime.datetime.now()
>>> print(f"datetime : {today}")
datetime : 2023-10-27 11:05:40.282314
>>> print(f"date time: {today:%m/%d/%Y %H:%M:%S}")
date time: 10/27/2023 11:05:40
>>> print(f"date: {today:%m/%d/%Y}")
date: 10/27/2023
>>> print(f"time: {today:%H:%M:%S %p}")
time: 11:05:40 AMCheck more formatting options.
Part 2 - https://www.reddit.com/r/Python/s/Tzx7QQwa7A
Thank you for reading!
Comment down other tricks you know.
r/Python • u/MisterBlggs • Jul 26 '19
Double Pendulum made with Processing.py
r/Python • u/DevJonPizza • Nov 09 '19
My First Algorithm in Python! A Recursive Maze Solver
r/Python • u/justKoda69 • May 15 '20
I Made This This morning I decided to learn how to code in Python and after watching a YouTube course on the basics of the language, I coded this all by myself. It took me like 4 or 5 hours. I feel ashamed and super proud at the same time.
r/Python • u/Itwist101 • May 27 '20
I Made This Circle Evolution v0.1 is now available on PyPI. My first big project as a 16 year old. [Github repo & desc in comments]
r/Python • u/knods • Nov 12 '19
6 Months of learning Python, 3 Hours of Rendering, here is my first Mandelbrot Zoom
r/Python • u/swizzex • Jul 16 '20
I Made This Learning python so my wife customized my tumbler.
r/Python • u/mutatedllama • Apr 09 '20
I Made This Dijkstra's algorithm now running in linear time on a 90x90 grid
r/Python • u/Im__Joseph • May 18 '21
Daily Thread Tuesday Daily Thread: Advanced questions
Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.
If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.
This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.
r/Python • u/raaaaaveNN • Dec 14 '19
I created a maze generator, then solved it with Djikstra's algorithm
r/Python • u/dartyet1 • Jun 18 '20
I Made This I made the rotating circle *illusion* from numberphile's lates video
r/Python • u/T0X1K01 • Oct 06 '20
Intermediate Showcase I made a program that gives me INFINITE STORAGE!
So, like the title says, I made a program using python that gives me infinite storage. More specifically it takes advantage of YouTube's infinite upload limit to use YouTube as a 100% free and unlimited cloud storage solution.
Demo video: https://youtu.be/yu_ZIr0q5rU
Source code (definitely still needs more work): https://github.com/AlfredoSequeida/fvid/
r/Python • u/OpenSourcerer420 • May 08 '20
I Made This My first Python program! Changes my desktop background based on the weather, time, and day.
r/Python • u/[deleted] • Jan 29 '21
Beginner Showcase This post has:
(Offline)
Hello! I made a little Program which gets statistics about this post! It should be update every 20 seconds.
This post has 2109 Upvotes!
It has 234 Downvotes
and 299 comments!
The 3 top comments are from:
|_Upvotes: 450
|_First word: I
|_Last word: account
|_Letters: 41
u/[deleted]
|_Upvotes: 59
|_First word: [removed]
|_Last word: [removed]
|_Letters: 9
|_Upvotes: 105
|_First word: ",
|_Last word: None
|_Letters: 7
u/[deleted]
|_Upvotes: 131
|_First word: EditingThisToSeeIfICangeTheFirstWordSetting.
|_Last word: AlsoChangingThisLOL!π
|_Letters: 86
|_Upvotes: 29
|_First word: "
|_Last word: "
|_Letters: 32
Note: Sometimes theres a Person with lesser upvotes on place 1, If people are disliking comments, the reddit api does weird things!
Second note: The Up/Downvotes and comments are NOT accurate!
Last update: 2021-02-06 20:11:24 CET
total updates: 21319
Latest comment by: u/_elbob
First word: testing
Last word: code
Letters: 16
Random Comment: Left to right unicode charecter
by: u/Valtsu0
This idea was inspired by u/Krukerfluk Krukerfluk's post: https://www.reddit.com/r/Python/comments/hoolsm/this_post_has/
My code on Github: https://github.com/Jonathan357611/Reddit-comment-statistics
This program is hosted on a Raspberry pi zero!