Newbie have thoughts about logic - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Newbie have thoughts about logic (/thread-34799.html) |
Newbie have thoughts about logic - sdd - Sep-01-2021 I have just started learning python and being a logical person and seeing this language with fresh new eyes I get curious about the logic in some of the rules. For instance, for x in "banana": print(x)I find this not logical. Instead I would use the word loop, like loop x in "banana": print(x)or why not even loop letters in "banana" verticallyThe word "loop" would be much easier to remember as it´s an english word that means what I want to do with x. The word "for" doesn't have that meaning in the english language forcing the newbie to memorize its meaning among so many other things to memorize. My point is - why not make python more logical and easy to learn and perhaps also use by adapting it more to the english language, whenever that's possible? RE: Newbie have thoughts about logic - Yoriz - Sep-01-2021 The for loop has been around for a long time. For loop if you use more descriptive variable names it reads a bit more like English for letter in "banana": print(letter) RE: Newbie have thoughts about logic - perfringo - Sep-02-2021 Consider this: - for-loop means 'for each' and 'for each letter in word' is very logical in my mind - for-loop is not the only loop in Python. There is also while-loop. Introducing 'loop' will therefore also introduce ambiguity (Python Zen: "In the face of ambiguity, refuse the temptation to guess") Programming languages are artificial languages ("a language whose rules are explicitly established prior to its use") contrary to natural language ("a language whose rules are based on current usage without being specifically prescribed"). Do you see problem here? 'explicit rules' vs 'current usage'? Also, if you learn any language you can't 'demand' or 'request' changes what are logical to you. My native language doesn't have gender-specific pronouns ('he', 'she') and it would be very logical for me to get rid of those words in english. We also don't have articles of noun ('a', 'the') and I still don't get why on earth these are necessary. However, english-native people don't understand nor recognize me and my problem(s) . RE: Newbie have thoughts about logic - Lou - Sep-02-2021 It could also be argued that you are not looping through the letters in banana. The intent is to "step" through the letters only once, Not loop through them several times. RE: Newbie have thoughts about logic - jefsummers - Sep-02-2021 I'd bet for loops are older than you are. Dartmouth Basic that I programmed in with punch cards, originally released 1964. Fortran 1957. The point being that the for loop is an established language construct. Using another word would confuse far more people than it would help. RE: Newbie have thoughts about logic - mishraakash - Sep-12-2021 Python is dynamically typed language. It has basically two types of loop
students = ['Peter', 'Camren', 'Andres', 'Jo', 'Geoff'] for name in students: print(name, len(name)) For loop can be used with list.,strings & tuples etc Can refer this article on QuizCure Different types of loops in python [/url] for more examples for loops in python. RE: Newbie have thoughts about logic - sdd - Sep-12-2021 Thanks for all replies! I question python because I believe it can be improved in terms of ease of learning and use, but being a newbie I'm probably wrong most of the time. Here's another one: txt = "The best things in life are free!" print("expensive" not in txt)Could it not be written like txt = "The best things in life are free!" check if("expensive" is not in txt)Why use the word "print" when you mean "Check if"? Print means something else in English. RE: Newbie have thoughts about logic - sdd - Sep-12-2021 (Sep-02-2021, 04:15 AM)perfringo Wrote: Consider this:Thank you for taking the time to answer. You wrote: "- for-loop means 'for each' and 'for each letter in word' is very logical in my mind" if for-loop means for each - why not simply use the for each expression in python instead of the for-loop expression? Then people didn't have to learn that for-loop really means for each. Maybe what I want is a computer that has learned my English instead of me having to learn python :) RE: Newbie have thoughts about logic - Yoriz - Sep-12-2021 https://docs.python.org/3/library/functions.html#print Wrote:print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)Just because you are using print to "check if" doesn't change what print is doing. If you really feel the need to make a new variable point to print you can. txt = "The best things in life are free!" check_if = print check_if("expensive" not in txt)
RE: Newbie have thoughts about logic - SamHobbs - Sep-13-2021 (Sep-01-2021, 10:33 PM)Yoriz Wrote: if you use more descriptive variable names it reads a bit more like EnglishYes the sentence for each letter in "banana" print the letter sounds valid to me. (Sep-12-2021, 06:01 PM)sdd Wrote: Why use the word "print" when you mean "Check if"? Print means something else in English.(This is a variation of what Yoriz said.) In the sample you provided, it is printing an expression and the expression is doing a check. The word print is misleading but I definitely do not considering it to be doing Check if; the checking is done by the expression, not the print function. (Sep-12-2021, 06:11 PM)sdd Wrote: why not simply use the for each expression in python instead of the for-loop expression?Many other languages often use inappropriate terms. Python is improved over the C language that would say: char banana[] = "banana"; int x; for (x = 0; x < strlen(banana); ++x) printf("%c\n", banana[x]); If you want a language that is defined to be understandable to non-developers then look at COBOL; COBOL loops are described in COBOL - Loop Statements. |