Layer 2 switch only does layer 2 forwarding, as such it doesn’t have any additional ip interfaces. On a layer 2 switch the ip address is assigned to the vlan interface instead.

config t
interface vlan 1
ip address 192.168.1.1 255.255.255.0
!

L2 switch you just can assign ip to  only “one” vlan at the time i.e. If you assigned ip to vlan1 then you try to assign an ip to vlan20 switch will shut down vlan1 and  bring up  vlan20 interface.

Layer 3 switch you can have multiple ip interfaces and can assign ip to physical interface.

config t
int fa0/1
ip address 192.168.1.1 255.255.255.0
!
int vlan 1
ip address 192.168.2.1 255.255.255.0