| | |
print no
![]() |
•
•
Join Date: Nov 2007
Posts: 148
Reputation:
Solved Threads: 33
See the answer from this thread
http://www.daniweb.com/forums/thread164796.html
Modify as appropriate.
http://www.daniweb.com/forums/thread164796.html
Modify as appropriate.
... and here is how you would do this with Python:
Just to compare the syntax, here is the same thing in C:
python Syntax (Toggle Plain Text)
arr = [12, 7, 9, 25, 87] for item in arr: print(item)
c Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int arr[] = {12, 7, 9, 25, 87}; int i; for(i = 0; i < sizeof(arr)/sizeof(int); i++) { printf("%d\n", arr[i]); } return 0; }
Last edited by Ene Uran; Dec 31st, 2008 at 9:47 am. Reason: see c
drink her pretty in burbank
There is "no beauty" in even simple C code! Let's all thank the Python development team for giving us a readable syntax. Come to think of it, they all were very fluent in C since the core of Python is writtten in C.
I guess the true beauty of C is somewhat hidden, it can do low level stuff more readable than assembly language.
I guess the true beauty of C is somewhat hidden, it can do low level stuff more readable than assembly language.
No one died when Clinton lied.
Its true ! Thanks Python Dev team. I saw one example from Ene where there was no indentation, I whoop it was horrible!
Anyway it is more readable than assembly but wait a minute snee, Assembly is more readable than 10000100101111, I mean a turbulent of machine code language!
Anyway it is more readable than assembly but wait a minute snee, Assembly is more readable than 10000100101111, I mean a turbulent of machine code language!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
Theist: It's okay, can you imagine anything else that doesn't exist?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
"Beauty is only in the eye of the beholder".
Those that know, find a well written piece of code in C very motivating and easy to work with.
The comparison of languages as it has been described here, only shows the lack of knowledge.
Those that know, find a well written piece of code in C very motivating and easy to work with.
The comparison of languages as it has been described here, only shows the lack of knowledge.
for(i = 0; i < sizeof(arr)/sizeof(int); i++) There's no need to evaluate sizeof(arr)/sizeof(int) every single time in the loop, since it never changes. Last edited by Aia; Jan 3rd, 2009 at 2:54 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan stating how a liberal's mind works.
•
•
•
•
I don't agree, because the compiler can see that sizeof(arr)/sizeof(int) never changes, so it certainly generates the code with a constant value. Isn't it a lack of knowledge Aia ? Knowledge, beauty, great philosophical problems to think about !
[As a way of clarification]
The comment about sizeof() was not the reference to lack of knowledge, but the comparison of languages base on syntax, which is why I said, "The comparison of languages as it has been described here".
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan stating how a liberal's mind works.
I tried comparing the assembly code produced when you remplace sizeof(arr)/sizeof(int) by the constant 5. The diff between the 2 programs is
So the difference is only one
Python Syntax (Toggle Plain Text)
< cmpl $4, -8(%ebp) < jle .L3 --- > movl -8(%ebp), %eax > cmpl $4, %eax > jbe .L3
movl instruction. >So the difference is only one
movl instruction.cmpl $4, -8(%ebp) is not the same that cmpl $4, %eax jle .L3 in not the same that jbe .L3 movl -8(%ebp), %eax is in a loop by virtue of "Jump if Below or Equal" Having the opportunity to execute many times. So it is not "only one mov1 instruction" executed only once. Last edited by Aia; Jan 3rd, 2009 at 9:17 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan stating how a liberal's mind works.
![]() |
Similar Threads
- internet explorer while trying to print (Web Browsers)
- Can't print the picture (Web Browsers)
- Print Center (OS X)
- Adding data to print job (Visual Basic 4 / 5 / 6)
- Outlook XP won't print (Windows NT / 2000 / XP)
- Page counter print accounting (*nix Software)
Other Threads in the Python Forum
- Previous Thread: Trouble implmenting Minheap algorithm!
- Next Thread: Indentation?
Views: 646 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for Python
application array beginner c++ c/c++ change character class client code command convert count create ctypes database dictionary django dll error examples excel exe extensions fdlib file float format framework ftp function graphics gui homework image images import input ironpython leftmouse library line linux list lists logging loop loops microcontroller mouse mysql mysqldb number numbers output parse parsing path port prime print processing program programming py2exe pygame pygtk pyqt python random raw_input recursion recursive redirect remote scrolledtext server size socket ssh stdout string strings table terminal text thread threading tkinter transparency tuple tutorial ubuntu unicode variable variables verify web windows wxpython






