C++ Vs Python Syntax Difference

In my humble opinion learning, by comparison, is the best way of learning, To stay in the loop while the industry is moving extremely rapidly, learning complex concepts by comparing to already familiar stuff is our best bet.

In this blog post, I will …


This content originally appeared on DEV Community and was authored by Natnael Getenew

In my humble opinion learning, by comparison, is the best way of learning, To stay in the loop while the industry is moving extremely rapidly, learning complex concepts by comparing to already familiar stuff is our best bet.

In this blog post, I will show you some common programs implemented in python and C++, So if you are trying to learn one of those languages or both at the same time! this post will serve you to learn in a comparable manner, let's dive in!

Hello World Program

  1. Hello World Program in python
print("Hello, World!")
  1. Hello World Program in C++

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}

Display Fibonacci Series

  1. Display Fibonacci Series in python
nterms = int(input("How many terms you want? "))  
# first two terms  
n1 = 0  
n2 = 1  
count = 2  
# check if the number of terms is valid  
if nterms <= 0:  
   print("Please enter a positive integer")  
elif nterms == 1:  
   print("Fibonacci sequence:")  
   print(n1)  
else:  
   print("Fibonacci sequence:")  
   print(n1,",",n2,end=', ')  
   while count < nterms:  
       nth = n1 + n2  
       print(nth,end=' , ')  
       # update values  
       n1 = n2  
       n2 = nth  
       count += 1  
}
  1. Display Fibonacci Series in C++

#include <iostream>  
using namespace std;  
int main() {  
  int n1=0,n2=1,n3,i,number;    
 cout<<"Enter the number of elements: ";    
 cin>>number;    
 cout<<n1<<" "<<n2<<" "; //printing 0 and 1    
 for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed    
 {    
  n3=n1+n2;    
  cout<<n3<<" ";    
  n1=n2;    
  n2=n3;    
 }    
   return 0;  
   } 

weather If you already know cpp and trying to learn python or vice-versa I hope you get the general gist of the Syntax difference between the two languages,
If you like this and this method of learning things, I have a repository dedicated to comparing programming languages and concepts, you can check it out on github


This content originally appeared on DEV Community and was authored by Natnael Getenew


Print Share Comment Cite Upload Translate Updates
APA

Natnael Getenew | Sciencx (2021-03-12T09:34:14+00:00) C++ Vs Python Syntax Difference. Retrieved from https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/

MLA
" » C++ Vs Python Syntax Difference." Natnael Getenew | Sciencx - Friday March 12, 2021, https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/
HARVARD
Natnael Getenew | Sciencx Friday March 12, 2021 » C++ Vs Python Syntax Difference., viewed ,<https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/>
VANCOUVER
Natnael Getenew | Sciencx - » C++ Vs Python Syntax Difference. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/
CHICAGO
" » C++ Vs Python Syntax Difference." Natnael Getenew | Sciencx - Accessed . https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/
IEEE
" » C++ Vs Python Syntax Difference." Natnael Getenew | Sciencx [Online]. Available: https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/. [Accessed: ]
rf:citation
» C++ Vs Python Syntax Difference | Natnael Getenew | Sciencx | https://www.scien.cx/2021/03/12/c-vs-python-syntax-difference/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.