Python Cheat Sheet
Python Cheat Sheet
boolean 1 bit
char 2 bytes
int 4 bytes
float 4 bytes
double 8 bytes
Date_time 4 bytes
// Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
//python
print("Hello World")
num="hello"
num2="komal"
print(num,num2)
print(num,num2,"from insta")
print("ist str = {0} , iind str= {1} ". format(num,num2))
//c++
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cout << "Enter two integers: ";
cin >> a >> b;
c = a+ b;
cout << a << " + " << b<< " = " <<c;
return 0;
}
num1 = 1.5
num2 = 6.3
a=10
b=20
Comment
Comments starts with a # (for single line), and Python will ignore them:
Comments starts with a """ ……………… """ (for multiple line), and Python will ignore
them:
The following example allows user to read an integer form the System.in.
import java.util.*;
class UserInputDemo
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in); //System.in is a standard input stream
System.out.print("Enter first number- ");
int a= sc.nextInt();
System.out.print("Enter second number- ");
int b= sc.nextInt();
System.out.print("Enter third number- ");
int c= sc.nextInt();
int d=a+b+c;
System.out.println("Total= " +d);
}
}
string firstName;
string fullName;
cout << "Type your first name: ";
cin >> firstName; // get user input from the keyboard
cout << "Your name is: " << firstName;
#include <iostream>
int main() {
int x, y;
int sum;
cout << "Type a number: ";
cin >> x;
cout << "Type another number: ";
cin >> y;
sum = x + y;
cout << "Sum is: " << sum;
return 0;
}
//python (getting input from user )
#simple string
name = input("Enter your name: ") # get user input from the keyboard
print("hello", name)