Syntax Description | Python | C++ |
including a module/library | from math import * | #include |
assignment operator | =, +=, -=, *=, /=, %= | same |
type integer value | int, long | short, int, long |
type decimal value | float | float, double, long double |
type boolean | bool: True/False or (not 0)/0 | bool: true/false or (!0)/0 |
type charactier | none | char |
type string | str | char mystring[50] or string |
for statement | for i in range(10): | for(i = 0; i < 10; i++) |
if statement | if x != 3: | if (x != 3) |
while statement | while x != 3: | while (x != 3) |
break out of a loop | break | same |
function definition | def myfunction(): | int myfunction() |
function call | myfunction() | same |
and operator | and | && |
or operator | or | || |
not operator | not | ! |
comparison operators | ==, !=, <, <=, >, >= | same |
arithmetic operators | +, -, *, /, % | same |
comments - single line | # | // |
comments - multiple lines | none | /* */ |
pre and post increment/decrement operators | none | ++x, x++, --x, x-- |
code blocks | indentation, ; | { } |
statement separator | end of line | ; |
constants | none | const int interest = .018 |
Input/Output | raw_input, input, print | cin, cout, and many others. |
Saturday, 3 June 2017
python vs C++
Syntax Comparison between Python and C++ (Partial Listing)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment