Python Basics



About

Python is very popular for being a much simpler and readable language. For example, let's look at a program that prints "Hello World!" in both Java and Python.

Java is a much more strict language, and information such as packages and classes must be identified in the code.
package java;
public class Print{
    public static void main(String[] args){
        System.out.println("Hello World!");
    }
}
              
In Python, this task can be accomplished in only one line.
print("Hello World!")

Python Basics (for programmers)


JavaPython
File Naming Program.java program.py
Output System.out.println("Hello World!"); print("Hello World!")
Variables int x=5;
String name="Mickey Engel";
x=5
name="Mickey Engel"
Input Scanner sc=new Scanner(System.in);
name=sc.nextLine();
name=input("Enter your name:")
Comments //single line comment
/*
multi-line comment
*/
#single line comment
"""
multi-line comment
"""
Concatenation "Hello, "+name; "Hello, "+name


Python Math and String Methods


JavaPython
Importing import java.util.Math; import math
Rounding Math.floor(x);
Math.ceil(x);
Math.round(x);
math.floor(x)
math.ceil(x)
math.round(x)
Comparisons Math.max(x,y);
Math.min(x,y);
min(x,y)
max(x,y)
Powers Math.pow(x,y);
Math.sqrt(x);
pow(x,y);
math.sqrt(x)
PI Math.PI math.pi()
Case Conversions str.toUpperCase();
str.toLowerCase();
str.upper()
str.lower()
String Length str.length(); len(str)
Substrings str.substring(start, end); str[start, end]