embedded system,Arduino,Raspberry pi,ARM7,MM32,STM32,PIC and Python,Django,Datascience and web development
Wednesday, June 19, 2019
list arrays in python
nameslist = ["Sam", "Lisy", "Pit"]
numberslist = [1, 2, 3.14]
mixedlist = ["ham", 'eggs', 3.14, 5]
and append function in python
a=[0,1,2]
print(a)
a.append(5)
a.append( "Zapzoo")
print(a)
output:
empty array is created like this
x=[]
array with zero initialisation values
y= [0]*10 # array of integers with 10 zero elements
z = [0.0]*20 # array of floats with 20 zero elements
numberslist = [1, 2, 3.14]
mixedlist = ["ham", 'eggs', 3.14, 5]
and append function in python
a=[0,1,2]
print(a)
a.append(5)
a.append( "Zapzoo")
print(a)
output:
empty array is created like this
x=[]
array with zero initialisation values
y= [0]*10 # array of integers with 10 zero elements
z = [0.0]*20 # array of floats with 20 zero elements
Tuple in python
Tuple is similar to list but
list is indicate in '[]'square brackets and tuples indicates in "()" parenthesis(optional)
another difference is list in mutable
tuple is immutable
empty tuple
t=()
example 1:
list=[10,20,30,40]
tuple=(10,20,30,40)
print(list)
print(tuple)
output:
[10, 20, 30, 40]
(10, 20, 30, 40)
example 2:
list=[10,20,30,40]
tuple=(10,20,30,40)
tuple2=10,20,30,40
print(list)
print(tuple)
print(type(tuple2))
print(tuple2)
output:
[10, 20, 30, 40]
(10, 20, 30, 40)
<class 'tuple'>
(10, 20, 30, 40)
example 3:
(x,y) = (5, 3)
coordinates = (x,y)
print(coordinates)
dimensions = (8, 5.0, 3.14)
print(dimensions)
print(dimensions[0])
print(dimensions[1])
print(dimensions[2])
output::
(8, 5.0, 3.14)
8
5.0
3.14
Taking input from user using python
Example 1:
s = input("What is your name?\n");
print("HELLO ", s);
output:
What is your name?
anil
HELLO anil
Example 2:
x = int(input("Input an integer: "))
y = float(input("Input a float: "))
print(x, y)
output:
Input an integer: 2
Input a float: 2.5
2 2.5
s = input("What is your name?\n");
print("HELLO ", s);
output:
What is your name?
anil
HELLO anil
Example 2:
x = int(input("Input an integer: "))
y = float(input("Input a float: "))
print(x, y)
output:
Input an integer: 2
Input a float: 2.5
2 2.5
reading hex values from char array
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned char start[2]={0x01,0x02,0x00};
printf("start[0]=%x\n",start[0]);
printf("start[1]=%x\n",start[1]);
// printf("start[2]=%x\n",start[2]);
return 0;
}
#include <stdlib.h>
int main()
{
unsigned char start[2]={0x01,0x02,0x00};
printf("start[0]=%x\n",start[0]);
printf("start[1]=%x\n",start[1]);
// printf("start[2]=%x\n",start[2]);
return 0;
}
Subscribe to:
Posts (Atom)
-
How to do the programming python in windows command prompt Step 1: please go through below link website f...
-
Serial.print() Description Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers a...