Can someone tell me what is the difference between while(1) and while (true) in python?

Recommended Answers

All 7 Replies

Latter causes uninitialized variable error if true variable is not defined. Python is case sensitive.

Please use True (it is capitalized) ...

# initialize count
count = 0
# you could use 1 instead of True, but True is clearer
while True:
    count += 1
    # exit condition needed to stop endless loop
    if count > 8:

'''result ...

ok can you tell me what does this mean :
string = ''.join(c for c in string if c.isalpha()) ?

Filter only letters from string.

The generator expression says, return a list of characters for every alphabetical character in string. The .join() method (applied to an empty string, and taking the generated list as it's argument) then fuses the list elements into a new string, with no separator character between them. The practical upshot of it is to filter out any character in string that isn't a letter.

what does this mean ord(a) - 97?

>>> chr(97)

So look like you are desiphering code dealing with number of letter in alphabet, probably Caesar "crypto" Actually your references to code look similar to my code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.