Bottom Page

Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Newb question about %02d %04d
As mention it gives more flexibility to have a function with parameters,than a limited print statement.
So what did we do print character at one line with between space in python 2?
# Python 2
>>> s = 'hello'
>>> for c in s:
...     print c
>>> for c in s:
...     print c,   
h e l l o
Ohhh adding , magically print it at one line with space,that's short and readable Snooty

If look at help on print() function Python 3,we see that there more choices.
>>> help(print)
Help on built-in function print in module builtins:

    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.
So Python 3 more flexibility and readable than magically ,.
# Python 3
>>> s = 'hello'
>>> for c in s:
...     print(c, end=' ')
h e l l o 
>>> for c in s:
...     print(c, end='\t')
h	e	l	l	o	
>>> for c in s:
...     print(c, end='**')
Not to mention
>>> print(*'hello', sep='**')
(Jan-06-2019, 01:35 PM)bennylava Wrote: Well I've got a question about python 3 already. Why did they switch to having a parenthesis if you want to print a string? In python to you didn't have to have parenthesis.

Because it makes sense for it to be a function, instead of a magic statement. One of the core ideas of python is that it's clean and legible, and magic statements are neither clean nor legible. It's also the only statement in the language which caused side effects. And because it was a statement, you couldn't use it everywhere (like in lambdas, or lists).
I have another question that relates to most of the discussion in this thread. Would you guys say that python 2 is very similar to python 3? Or were there some pretty significant changes? Is it more similar than it is different?
I would say it's definitely more similar than different, but there were some significant changes that made python3 even better programming language than python2
Well the reason I ask is because I think today I've... hit a wall. I'm beginning to question the wisdom of jumping ship in the middle of learning Python 2. I'm starting to think that I should just finish python 2 on code academy, and try to get a certificate. Then, work for a year somewhere (wherever I can) and really learn from on the job experience. Then, once it can be said that I understand it well, then upgrade to the better language that is Python 3.

I'm thinking my trouble stems from Code academy, to me it seems they've really dropped the ball on their Python 3 lessons. They're not nearly as good as the Python 2 lessons in my opinion. So much so that I'm considering going elsewhere to learn, and asking for a refund. It looks to me like they're attempting to take too many shortcuts with their teaching. Likely saving them time and money in the process.

So I'm kind of at a stopping point in my studies of programming, which for me really sucks. As I desire to keep moving forward. But I have to figure out the best thing to do.
Once you know python 2, the difference in syntax between that and python 3 are so minimal, you can switch over in minutes.
To read this thread you'd think it was a bad idea to learn python 2. As "They'll stop supporting it soon." That is what put me off of that idea.
If that particular method of learning is better suited for python 2, then go for it. Just, once you're done, look up what's changed in 3.x, and use 3.x for projects once you're done learning.
Well I got a couple of more questions for you guys.

1. Does the code below seem convoluted to yall? Particularly the part where they had me do str(row_count). What is the purpose of that? If you were making a spreadsheet, why wouldn't you just set the number of rows to be 1,000? They lose me on some of this stuff.

2. My next question is in regards to commas. Its little things like this that hang me up. How do you know when you can use a comma, and when you can't? Again if you look below, you can see the use of commas. But I've tried to use them in some situations, and things just didn't work out. This sounds like a dumb question to me but: Wouldn't python just disregard the commas if you couldn't use them? Can someone go into when you can use commas, and when you can't?

# Define create_spreadsheet():
def create_spreadsheet(title, row_count = 1000):
  print("Creating a spreadsheet called " + title + " with " + str(row_count) + " rows")

# Call create_spreadsheet() below with the required arguments:
create_spreadsheet(title = "Applications", row_count = 10)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Simple newb string question Involute 2 351 Sep-08-2019, 12:50 AM
Last Post: Involute
  please help this newb install pygame iofhua 7 1,128 May-15-2019, 01:09 PM
Last Post: buran
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 435 Apr-15-2019, 06:19 AM
Last Post: perfringo
  Pthyon 3 question (newb) bennylava 11 1,120 Feb-28-2019, 06:04 PM
Last Post: buran
  newb selfie PatM 5 619 Feb-19-2019, 12:20 AM
Last Post: snippsat
  Complete NEWB and openpyxl project Netopia 44 4,032 Jan-18-2019, 08:15 PM
Last Post: Netopia
  Newb Question - Threading in Crons vvarrior 2 749 Jul-20-2018, 08:12 PM
Last Post: vvarrior
  Matt's newb question 1 MattSS102 1 1,035 Aug-28-2017, 03:27 AM
Last Post: BerlingSwe
  Newb: Simple Explicit Formula Duplicitous 1 1,252 May-05-2017, 07:03 PM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)