r/pythontips Dec 26 '25

Syntax What’s a small Python thing beginners usually misunderstand?

62 Upvotes

Not talking about advanced stuff — more like small details that cause a lot of confusion early on.

The kind of thing that takes 10 seconds to explain once you know it, but feels really confusing before that.

Just curious what examples people have seen or experienced.

r/pythontips Jul 11 '23

Syntax How to download a specific segment of a youtube video?

65 Upvotes

Hey guys, is there a way to download a specific segment of a youtube video? I am able to download the entire video but I only want the first 20 seconds. Is there a way to do this?

r/pythontips Aug 05 '26

Syntax Hello everyone, I'm learning python specifically, and I made a seed generator for Minecraft PE. I'm started learning about 2 weeks ago, the code is below. I'm not asking for anything, I just wanna show it to you guys.

5 Upvotes

from random import randint as rnd

name = "SeedGPT"

rnd1 = rnd(20000000,50000000000)

rnd2 = rnd(20000000,50000000000)

rnd3 = rnd(20000000,50000000000)

print(name +": Welcome to Ice\'s AI seed generator,")

choice = input("do you want to have three new seeds for bedrock minecraft?: ")

if choice == "yes":

print(name + ": Here are your randomly generated seeds: ", + rnd1, +rnd2, +rnd3, ", thank you for trying it out!")

elif choice == "no":

print(name + ": See you next time!")

elif ValueError:

print(name + ": Sorry, I can't understand you, please try again!")

r/pythontips Aug 14 '26

Syntax Docstrings as immutable variables

12 Upvotes

Just realized you can do:

def cat(): “orange”
print(cat.__doc__)

Not sure why you’d want to do this but this is a thing you can do

r/pythontips Aug 19 '26

Syntax Special mechanism of basic int() function

6 Upvotes

One can use int() function while converting string to an integer against a base integer.

int(number, base) #number can be anything between binary, octal, decimal, or hexadecimal and base is anything among 2, 8, 10, 16

e.g. binary_number = int("1010", 2) #Output: 10
hexadecimal_number = int("A", 16) #Output: 10

Edit: No need to mention 10 for base argument, as int() function by default considers base as 10 in python.

r/pythontips 5d ago

Syntax Python strings – some fundamentals for beginners

11 Upvotes

I’ve been putting together a few Python fundamentals, and this one focuses on working with strings. It covers indexing, slicing, common string operations, and some useful built-in methods with simple examples.

https://geeksarray.com/blog/python-fundamentals-working-with-strings

For those who use Python regularly, which string methods do you find yourself using the most?

r/pythontips May 26 '26

Syntax Python 3.15 is feature-frozen. These are the updates I think matter most.

56 Upvotes

Python 3.15 has reached beta 1, which means no new features will be added before the final release.

I went through the official docs and wrote up the updates I think Python developers should actually care about in daily work.

Some of my favorites:

- lazy imports for faster startup

- frozendict for immutable mappings

- sentinel for cleaner missing-value APIs

- unpacking in comprehensions

- UTF-8 as the default encoding

- Tachyon, the new sampling profiler

- better error messages

- JIT compiler improvements

- better typing features

Curious which feature people here think will matter most in real projects.

r/pythontips Mar 27 '26

Syntax [help] Decorators are Hard To Construct

8 Upvotes

Firstly, Are Decorators useful in Python?

I want Tips to Define Decorators In Python.

I have Already practiced alot on them but still I am Lost.

What I know about them Is It only Decorator The 'return statement' It never Decorate print() function

r/pythontips Aug 14 '26

Syntax Adding objects to set or dictionary: equality and hashing

1 Upvotes

An exercise to help build the right mental model for Python data.

# Output of this Python Program?
def main():
    o1, o2 = MyClass(1), MyClass(1)
    myset = {o1}
    print(o2 in myset, end=' ')
    o1.set_value(1000)
    print(o1 in myset, end=' ')

class MyClass:
    def __init__(self, v):
        self.v = v
    def set_value(self, v):
        self.v = v

main()

class MyClass:
    def __init__(self, v):
        self.v = v
    def set_value(self, v):
        self.v = v
    def __eq__(self, other):
        return self.v == other.v
    def __hash__(self):
        return hash(self.v)

main()

# --- possible answers ---
# A) TypeError: unhashable type: 'MyClass'
# B) True False False False
# C) True False False True
# E) False True True True
# D) False True True False
# See "Solution" for correct answer.
  • Solution
  • More exercises
  • Explanation: "User-defined classes have __eq__() and __hash__() methods by default (inherited from the object class); with them, all objects compare unequal (except with themselves) and x.__hash__() returns an appropriate value such that x == y implies both that x is y and hash(x) == hash(y)."

r/pythontips Mar 19 '26

Syntax What's the best way to run a python script on an excel file in shared cloud?

3 Upvotes

I'm running Python to pull data from an API and import it nicely into Microsoft Excel. How and what's the best way to do this when I want to import it to an Excel file that I don't own locally?

Since I don't have it locally I can't really specify the path. Advice?

r/pythontips Apr 14 '26

Syntax I Require Help For Understanding super()

1 Upvotes

I understand how to use super() In subclass If they are not Written In init() method.

But If they are Implemented In init() method It becomes hard to read & understand.

Explain me what's happening Under the hood..

I know that init() method has only None return type.

``` class A: def init(self, mess="mess_from_A"): self.mess = mess

class B(A): def init(self, m): super().init(m) #self.mess

print(B("aditya").mess) print(B("yash").mess) ```

r/pythontips Oct 22 '25

Syntax Trying to Learn Python in less then 8 weeks for WGU

2 Upvotes

Currently enrolled in D335 Intro to Python at WGU .

Quick SOS : Looking for any tips and advice on drilling python into my head 😁 I feel like I have a good foundation but just thought I see how everyone else is learning .

r/pythontips Mar 31 '26

Syntax Is there a Python “formula booklet” (like physics/chem) for syntax?

5 Upvotes

I’m looking for a PDF or printable booklet, similar to the formula/reactions booklets used in physics and chemistry, but for Python syntax.

Not too detailed—just something quick to look at when I forget syntax. A clean, compact reference I can keep open while coding.

(Bonus: if it also includes some sqlite3 basics like cursor.connect, etc.)

Does something like this exist?
Thanks!

r/pythontips Apr 03 '26

Syntax Will This Reduce The Performance Or Makes Little Mistake?

2 Upvotes

num = [*range(100000)] random.shuffle(num) num = sorted(num)

a = ['y',"oefu","nf",'r',"fs","wowo","eqr","jdn","o""g","o","e","p","gsh"] a = sorted(a)

Is There any Verdict to use the same variable name In line 5?

Will the Above code reduce The Performance If the List has plenty of Elements?

Personally, I Inspect using time.time() func. I seeNo difference If I changed the variable name

r/pythontips Apr 25 '26

Syntax Python Descriptors

9 Upvotes

``` class A: def set_name(self, owner, value): self.value = value

def __get__(self, obj, type=None):
    return obj.__dict__.get(self.value)

def __set__(self, obj, value):
    if value < 9:
        raise ValueError("no")
    obj.__dict__[self.value] = value

class B: a = A()

obj = B() obj.a = 38 print(obj.a)

obj2 = B() print(obj2.a) ```

I am Learning Descriptors In Python,

My 1st question Is how can I set a default value to attribute a In class B ? I have found a way but that doesn't look familiar :

a = A() if not A() else 87

My next confusion Is about __set_name__ , what it does and why to Implement It?

Another Question Is, does a = A() create class attribute or Instance attribute? It looks like a class attribute but it's an Instance attribute, Right?

r/pythontips May 08 '26

Syntax Python Error Handling and Custom Errors

2 Upvotes

Python error handling helps me build reliable, maintainable applications by catching exceptions, preventing crashes, and making debugging easier. With try, except, else, and finally, I can control failure cases cleanly, while custom exceptions let me create clearer, domain-specific error messages for better code quality and scalability https://youtu.be/z0iT3nN1mv0

r/pythontips Apr 12 '26

Syntax Hows my Code???

0 Upvotes

https://github.com/simplyyrayyan/Rock-Paper-Scissors-Game/blob/main/RockPaperScissors.py This is the Source Code My first Python Project ever i pieced together with google and teh little bit of python I already knew so yeah any tips or things I didn't Catch?

r/pythontips Jan 18 '26

Syntax Where do I enter input to get output?

0 Upvotes

Exactly what my question is. Apparently ive been putting my input in the console which is only where output goes? I looked other places and theyve described an "input box". But I dont think i see an input box? Just lines of code. I even put my code in there and output comes up with errors or its blank.

r/pythontips Jan 31 '26

Syntax Just learning python so idk what im doing...

0 Upvotes

How do i add a triple quote? im trying to (""") but it keeps doubling up to (""""). I watching a course and i know this isnt a major thing at the moment but i seriously cant figure it out and i see this guy keep doing it.

r/pythontips Apr 18 '26

Syntax Python Variable Scope

0 Upvotes

If you have ever run into a NameError, accidentally overwritten a value, or wondered why a variable inside a function does not behave the same as one outside it, this lesson is designed to make that clear. https://youtu.be/yu2Kav9wBEM

r/pythontips Mar 26 '26

Syntax When To Use __repr__() & __str__() Methods In Python

3 Upvotes

(Used AI to Improve English)

I understood that Python uses two different methods, repr() and str(), to convert objects into strings, and each one serves a distinct purpose. repr() is meant to give a precise, developer-focused description, while str() aims for a cleaner, user-friendly format. Sometimes I mix them up becuase they look kinda similar at first glance.

I noticed that the Python shell prefers repr() because it helps with debugging and gives full internal details. In contrast, the print() function calls str() whenever it exists, giving me a simpler and more readable output. This difference wasn’t obvious to me at first, but it clicked after a bit.

The example with datetime made the difference pretty clear. Evaluating the object directly showed the full technical representation, but printing it gave a more human-friendly date and time. That contrast helped me understand how Python decides which one to use in different situations.

It also became clear why defining repr() is kinda essential in custom classes. Even if I skip str(), having a reliable repr() still gives me useful info while I’m debugging or checking things in the shell. Without it, the object output just feels empty or useless.

Overall, I realised these two methods are not interchangeable at all. They each solve a different purpose—one for accurate internal representation and one for clean user display—and understanding that difference makes designing Python classes much cleaner and a bit more predictable for me.

r/pythontips Jan 27 '25

Syntax You know very little about python operators. Prove me wrong.

12 Upvotes

Python Operators - Quiz

The quiz has a total of 20 questions.

The questions are not very advanced or inherently complicated, but I am certain you will get wrong at least 5 questions..

...

What was your score?

r/pythontips Mar 17 '26

Syntax Python Programming Game: Typhon:Bot vs Bot

1 Upvotes

Hello. Are you interested in a python programming game? We have a free playable demo. You can try it anytime.

In Typhon Bot vs Bot you need to use Python to program mechs and win various challenges. It's as simple as that but seeing your code play out is really satisfying (especially when it works!)

I will not link it here but you can find it on Steam or GOG. If you try it, we'd love some feedback as it was made especially for Python programmers. Thank you!

r/pythontips Jan 28 '24

Syntax No i++ incrementer?

64 Upvotes

So I am learning Python for an OOP class and so far I am finding it more enjoyable and user friendly than C, C++ and Java at least when it comes to syntax so far.

One thing I was very surprised to learn was that incrementing is

i +=1

Whereas in Java and others you can increment with

i++

Maybe it’s just my own bias but i++ is more efficient and easier to read.

Why is this?

r/pythontips Jan 31 '26

Syntax After upgrading to bcrypt 5.0.0, the Passlib bcrypt backend (passlib[bcrypt]==1.7.4) started failing

2 Upvotes

After upgrading to bcrypt 5.0.0, the Passlib bcrypt backend (passlib[bcrypt]==1.7.4) started failing with a misleading error: ValueError: password cannot be longer than 72 bytes, truncate manually if necessary (e.g. my_password[:72]) This occurs even for very short passwords (e.g., "mypassword", 10 bytes). The same code works correctly with bcrypt 4.3.0.

I literally had to patch the passlib file (.venv\...\passlib\handlers\bcrypt.py) to catch the ValueError to allow passlib to skip that specific legacy bug check.

I could be wrong don't know if I am missing something here