0

am using python for visual studio 2012 (PTVS2012). So far I only know C# and I have just started learning Python. I have a couple questions

  1. Ok so in C# from my knowledge you just make a method of any type such as an integer followed by the parameters such as static void Main(). In python the only method I know of right now is def Main() but am sure I will learn how to code more methods. In C# braces surround a block of code inside a method. Does python need braces aswell because in PTVS it is giving me this "expected an indent block" whenever I try to put braces in a method. For example the code sample below is giving me this error. Basically do I need braces or not?

    def Main(): {

    }

  2. How to indent in PTVS? Like if you use c# in PTVS it indents automatically and it just makes the code nicer to look and understand

  3. Guess this is a follow up from number 2, in my tutorial right now for python am learning how to do loops which I already know from C#. So for example

    a = 0

    while a < 10:
    
    a = a + 1
    
    print (a)
    

In C# you would incase the code to be executed in the loop using braces and indent it also? Does python need braces and indenting aswell in PTVS?

Pavel Minaev
  • 99,783
  • 25
  • 219
  • 289
Foysal94
  • 565
  • 2
  • 7
  • 15
  • 1
    Not really a question that needs the attention of C# folks... Removing tag. Also, python and C# are very different languages... you should just find a python book or just google for examples if you need help with python syntax. – tnw Jan 20 '14 at 21:50

1 Answers1

0

No, python does not use braces, it uses indentation using the tab character to specify which lines belong to which code block.

See for example http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Indentation

C function

void foo(int x)
{
    if (x == 0) {
        bar();
        baz();
    } else {
        qux(x);
        foo(x - 1);
    }
}

Python function:

def foo(x):
    if x == 0:
        bar()
        baz()
    else:
        qux(x)
        foo(x - 1)

Find a good book or course on python to get you started. https://wiki.python.org/moin/BeginnersGuide/Programmers

flup
  • 26,937
  • 7
  • 52
  • 74